我已经创建了矩阵列表,现在我想要在所有矩阵中获得最大值的行,我如何得到它们?从列表中的所有矩阵中获得最大值
下面是列表的代码:
i <- 1
tryList <- list()
treeList <- list()
accList <- list()
for(t_mtry in 1:40){
for(t_ntree in 20:300{
rf <- randomForest(class ~., data=training, mtry=t_mtry, ntree=t_ntree)
tbl <- table(predicted = predict(rf,evalSet,type="class"),actual=evalSet$class)
#get the accuracy of the classification as a list
retVal <- accuracy(tbl)
tryList <- c(tryList,t_mtry)
treeList <- c(treeList,t_ntree)
accList <- c(accList,mean(retVal))
}
matrixList[[i]] <- matrix(c(tryList,treeList,accList),length(accList)
i <- i + 1
tryList <- list()
treeList <- list()
accList <- list()
}
现在我想从每一个矩阵accList的最大值。 如果我有一个矩阵我使用:
lapply(matrix,max)
max(unlist(matrix[,3]))
但我怎么可以用它与列表?
我想你的术语可能有点过这里。如果你喜欢'矩阵',你评估每一个元素。你能提供一个可重复的例子(这个不运行,有两个紧邻的括号丢失,库(randomForest)没有声明)? – 2012-03-12 07:44:55