1
让我们先从一些简单的代码:的R - 列表作为参数的传递元素函数调用
require(randomForest)
randomForest(mpg~.,mtcars,ntree=10)
这建立的10棵随机森林。
我想要的是将参数存储在列表中而不是进行函数调用。像这样:
require(randomForest)
l<-list(ntree=10)
randomForest(mpg~.,mtcars,l[[1]])
但是,这是行不通的。错误消息是:
Error in if (ncol(x) != ncol(xtest)) stop("x and xtest must have same number of columns") : argument is of length zero
这表明randomForest的参数xtest = NULL设置为10而不是ntree。
这是为什么?我如何将参数ntree作为列表元素传递?
谢谢。
感谢。它的确如此,但我想在列表中指定应该设置哪个参数。 – Julian