我已經創建了矩陣列表,現在我想要在所有矩陣中獲得最大值的行,我如何得到它們?從列表中的所有矩陣中獲得最大值
下面是列表的代碼:
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