Reputation: 277
I want to set different sampsize for randomForest in R. I expect to see 3 different RF return, but the error occured in R "(list) object cannot be coerced to type 'integer'"
and my code is as follows
sampsize_vect<-vector("list",3)
sampsize_vect[[1]]<- rep(6670,3)
sampsize_vect[[2]]<- c(1000)
sampsize_vect[[3]]<- c(5000,5000)
for (i in 1:3) {
RF <- randomForest (x,y,sampsize=sampsize_vect[i],node.size=3,do.trace=FALSE,importance=TRUE,ntree=150,,forest=TRUE)
print(RF)
}
Why this happened and how to solve this problem.
Upvotes: 0
Views: 1218
Reputation: 173537
It doesn't have anything to do with the random forests. You simply used [
when you should have used [[
(or vice versa, I suppose).
Change sampsize = sampsize_vect[i]
to sampsize = sampsize_vect[[i]]]
. Always remember, with lists [[
selects an element while [
selects a sub-list.
Upvotes: 2