在R中的数组中保存积分值

在R中的数组中保存积分值,r,integration,R,Integration,我想将整数值保存在一个数组中。例如,在下面的程序中,从q=1到q=10。但是由于输出带有非数字部分,因此无法执行此操作。请提供帮助 q=10 integrand<-function(x)(q*x^3) integrate(integrand,lower=0,upper=10) q=10 被积函数str()是解决这个问题的朋友: > intval <- integrate(integrand,lower=0,upper=10) > str(intval) List of

我想将整数值保存在一个数组中。例如,在下面的程序中,从q=1到q=10。但是由于输出带有非数字部分,因此无法执行此操作。请提供帮助

q=10
integrand<-function(x)(q*x^3)
integrate(integrand,lower=0,upper=10)
q=10
被积函数
str()
是解决这个问题的朋友:

> intval <- integrate(integrand,lower=0,upper=10)
> str(intval)
List of 5
 $ value       : num 25000
 $ abs.error   : num 2.78e-10
 $ subdivisions: int 1
 $ message     : chr "OK"
 $ call        : language integrate(f = integrand, lower = 0, upper = 10)
 - attr(*, "class")= chr "integrate"
然后:


integrandParse它并只存储所需的第一部分。
> intval$value
[1] 25000
integrand<-function(x,q=10)(q*x^3)
tmpfun <- function(q) {
    integrate(integrand,lower=0,upper=10,q=q)$value
}
sapply(1:10,tmpfun)
##  [1]  2500  5000  7500 10000 12500 15000 17500 20000 22500 25000