【发布时间】:2021-04-14 16:04:33
【问题描述】:
是否可以从 R 中的数据框计算积分?
示例。
t <- data.frame(x1 = c(200),
x2 = c(2),
x3 = c(1:500))
如果 t 是表,是否可以像其他操作一样生成具有积分结果的新列?
我尝试使用此代码,但它不起作用。
Func <- function(z) {(t$x1+t$x2+t$x3)*z}
t$new <- integrate(Func, lower = 1, upper = 2)
【问题讨论】:
-
阅读这个函数
integrate()的文档,这是我发现的:函数必须是an R function taking a numeric first argument and returning a numeric vector of the same length.你的函数接受一个数字并返回一个500元素长的向量。 -
你的函数应该如何工作?
标签: r dataframe dplyr integral