这个错误是什么意思?

时间:2017-05-21 18:07:04

标签: r

代码:

pvalue <- matrix(nrow = 9, ncol = 10000)

for(i in 1:9) {
   for(j in 1:10000) {
    pvalue[i,j]=integrate(dnorm,0,1)    
   }
}

错误:

Error in pvalue[i, j] <- integrate(dnorm, 0, 1) : number of items to
replace is not a multiple of replacement length`

1 个答案:

答案 0 :(得分:1)

integrate(dnorm,0,1)的输出是一个列表,而不是数字。

str(integrate(dnorm,0,1))

List of 5
 $ value       : num 0.341
 $ abs.error   : num 3.79e-15
 $ subdivisions: int 1
 $ message     : chr "OK"
 $ call        : language integrate(f = dnorm, lower = 0, upper = 1)
 - attr(*, "class")= chr "integrate"

工作代码是:

pvalue <- matrix(nrow = 9, ncol = 10000)

for(i in 1:9) {
   for(j in 1:10000) {
    pvalue[i,j] <- integrate(dnorm,0,1)$value    
   }
}