使用R可以提取多个点的函数的值吗

  • 本文关键字:函数 提取 使用 r probability ecdf
  • 更新时间 :
  • 英文 :


大家好,感谢阅读!

我使用rstudio构建了一个ecdf函数,并试图获得与某些点相对应的概率(列表格式(。我的R代码如下:

input <- read.table('/home/agalvez/data/domains/test_ecdf.txt', sep="t", header=TRUE)
#Build the function
myecdf <- ecdf(input$X118.4)
#Plot the function
plot(myecdf, main = "CDF", xlab = "Bit score", ylab = "Probability") +
abline(v = 25, col = "red")
#Extract probabilities
myecdf(100)

正如你所看到的,我能够一次提取一个点的概率。但如果我尝试获取多个,我会收到一条错误消息。我现在将附上我尝试过但没有成功的东西。

myecdf(100, 2, 4, ...)
Error in myecdf(100, 2, 4) : unused arguments (2, 4)
myecdf(100)
myecdf(2)
myecdf(4)
...
This approach gives me the results like this in the console:
> myecdf(100)
[1] 0.8048582
> myecdf(2)
[1] 1.382514e-05
> myecdf(4)
[1] 0.0005875684
I would like them to be a list.
myecdf(100,2,4,...)
Error in myecdf(100, 2, 4) : unused arguments (2, 4)

如果有任何帮助,我们将不胜感激,很抱歉打扰了这个简单的问题,但我对R很陌生,提前感谢!

您必须将所需的值定义为vector:

myecdf(c(100, 2, 4))