是否可以使用 R 提取多点函数的值?

Is it possible to extract the value of a function of multiple points using R?

您好,感谢阅读!

我使用 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 的新手,在此先感谢!

您必须将需要的值定义为向量:

myecdf(c(100, 2, 4))