【发布时间】:2011-12-10 14:04:10
【问题描述】:
我很好奇 R 是否能够将对象放入向量/列表/数组/等中。我正在使用 randomforest 包来处理大量数据的子集,并希望将每个版本存储在一个列表中。应该是这样的:
answers <- c()
for(i in 1:10){
x <- round((1/i), 3)
answers <- (rbind(answers, x))
}
理想情况下,我想做这样的事情:
answers <- c()
for(i in 1:10){
RF <- randomForest(training, training$data1, sampsize=c(100), do.trace=TRUE, importance=TRUE, ntree=50,,forest=TRUE)
answers <- (rbind(answers, RF))
}
这种方法可行,但这是单个 RF 对象的输出:
> RF
Call:
randomForest(x = training, y = training$data1, ntree = 50, sampsize = c(100), importance = TRUE, do.trace = TRUE, forest = TRUE)
Type of random forest: regression
Number of trees: 10
No. of variables tried at each split: 2
Mean of squared residuals: 0.05343956
% Var explained: 14.32
虽然这是“答案”列表的输出:
> answers
call type predicted mse rsq oob.times importance importanceSD
RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8
RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8
RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8
RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8
RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8
RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8
RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8
RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8
RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8
RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8
localImportance proximity ntree mtry forest coefs y test inbag
RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL
RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL
RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL
RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL
RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL
RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL
RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL
RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL
RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL
RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL
有谁知道如何存储所有 RF 对象或调用它们以使存储的信息与单个 RF 对象相同?感谢您的建议。
【问题讨论】:
标签: r list random-forest