【发布时间】:2012-03-28 14:54:07
【问题描述】:
我已经创建了一个矩阵列表,现在我想获取所有矩阵中行的最大值,如何获取它们?
这是列表的代码:
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]))
但是如何将它与列表一起使用?
【问题讨论】:
-
我认为您的术语可能有点偏离这里。如果您确实对
matrix进行了 lapply,那么您将评估每个元素。您能否提供一个可重现的示例(此示例无法运行,缺少两个右括号并且未声明 library(randomForest))?