问题描述
当我运行这段代码时-
a<- read.delim(file.choose("data.txt"))
d<-sort(a$d)
plot(d,sort(ecdf(d)(d)),type="s",lty=2,col="red",ylab= "P(X<=x)",ylim= 0:1)
这让我犯了这个错误-
Error in ecdf(d) : 'x' must have 1 or more non-missing values
帮助?
解决方法
我运行了您的代码,看来还好。我刚刚更改了代码的第二行,因为数据中提供的唯一列名为 x ,而不是 d 。
检查一下:
# load data
a = structure(list(x = c(4L,1L,0L,4L,2L,3L,5L,6L,1L)),class = "data.frame",row.names = c(NA,-100L))
# sort x column (the only column)
d = sort(a$x)
# plot
plot(d,sort(ecdf(d)(d)),type = "s",lty = 2,col = "red",ylab = "P(X<=x)",ylim = 0:1)
输出: