# 如何将函数应用于r中多个列表？

``````list(`Cluster 1` = list(Day_1 = list(structure(c(`1` = 0, `2` = 0,
`3` = 0, `4` = 0, `5` = 0, `6` = 0, `7` = 0, `8` = 0, `9` = 0.041,
`10` = 0.673, `11` = 0, `12` = 0.766), .Dim = 12L, .Dimnames = list(
c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
"12"))), structure(c(`1` = 0, `2` = 0, `3` = 0, `4` = 0,
`5` = 0, `6` = 0.041, `7` = 0.673, `8` = 0.766), .Dim = 8L, .Dimnames = list(
c("1", "2", "3", "4", "5", "6", "7", "8")))), Day_2 = list(
structure(c(`1` = 1.07, `2` = 0, `3` = 1.27, `4` = 0.19,
`5` = 0, `6` = 0, `7` = 0, `8` = 0, `9` = 0, `10` = 0, `11` = 0,
`12` = 0), .Dim = 12L, .Dimnames = list(c("1", "2", "3",
"4", "5", "6", "7", "8", "9", "10", "11", "12"))), structure(c(`1` = 1.07,
`2` = 1.27, `3` = 0.19, `4` = 0, `5` = 0, `6` = 0, `7` = 0,
`8` = 0), .Dim = 8L, .Dimnames = list(c("1", "2", "3", "4",
"5", "6", "7", "8"))))), `Cluster 2` = list(Day_3 = list(
structure(c(`1` = 0, `2` = 0, `3` = 0, `4` = 0, `5` = 0,
`6` = 0, `7` = 0, `8` = 0, `9` = 0.19, `10` = 0, `11` = 0,
`12` = 0), .Dim = 12L, .Dimnames = list(c("1", "2", "3",
"4", "5", "6", "7", "8", "9", "10", "11", "12"))), structure(c(`1` = 0,
`2` = 0, `3` = 0, `4` = 0, `5` = 0, `6` = 0.19, `7` = 0,
`8` = 0), .Dim = 8L, .Dimnames = list(c("1", "2", "3", "4",
"5", "6", "7", "8")))), Day_4 = list(structure(c(`1` = 0.521,
`2` = 0.229, `3` = 0, `4` = 0, `5` = 0, `6` = 0, `7` = 0, `8` = 0,
`9` = 0, `10` = 0, `11` = 0, `12` = 0), .Dim = 12L, .Dimnames = list(
c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
"12"))), structure(c(`1` = 0.75, `2` = 0, `3` = 0, `4` = 0,
`5` = 0, `6` = 0, `7` = 0, `8` = 0), .Dim = 8L, .Dimnames = list(
c("1", "2", "3", "4", "5", "6", "7", "8"))))))
``````

``````nested_lapply <- function(data, fun) {
lapply(data, function(sublist) { lapply(sublist, fun) })
}
``````

``````res<-nested_lapply(out, max)
Error in FUN(X[[i]], ...) : invalid 'type' (list) of argument
Called from: lapply(sublist, fun)
``````