R:将函数应用于嵌套列表的最后一级并保留名称和放大器结构体

时间:2014-10-01 15:41:11

标签: r list

m <- matrix(1:9, ncol=3)
list1 <- vector("list", 3)
list1 <- lapply(list1, function(x) x <- m)
list2 <- vector("list", 3)
list2 <- lapply(list2, function(x) x <- list1)
list2

我想得到一个与list2具有相同结构的对象,它包含矩阵函数的返回(在我的例子中为colMeans)。这应该适用于最多n维。

我正在玩耍筑巢,但它没有保留名字,我相信这里有人知道更聪明的方法。

谢谢!

1 个答案:

答案 0 :(得分:3)

rapply(list2, colMeans, how="replace")