简体   繁体   中英

The nested loop is producing this error: Non-numeric argument to mathematical function

I'm very new to R and I'm having trouble executing this script. The nested loop outputs a "Non-numeric argument to mathematical function" error. I'm not sure which argument in the nested loop is non-numerical? Any help on this would be greatly appreciated. Thanks.

library(emdbook)

prev<-read.delim("shape.txt", header=T)
shape1<-prev$shape1
shape1<-as.numeric(shape1)
shape2<-prev$shape2
shape1<-as.numeric(shape2)

pvec <- seq(0, 1, length=298)

postvec<-data.frame(posterior=1:298)
dim(postvec)

for (i in 1:length(shape1)) 
{
    for (j in 1:length(shape2)) 
    {
    postvec[i]<- dbeta(pvec, shape1= shape1[i], shape2=shape2[j])
}
}
prev<-read.delim("shape.txt", header=T)
shape1<-prev$shape1
shape1<-as.numeric(shape1)
shape2<-prev$shape2
shape1<-as.numeric(shape2)

Should that last line say:

shape2<-as.numeric(shape2)

?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM