Here is one approach that uses meltand dcastfrom "reshape2".
library(reshape2)
#
x <- melt(mylist)
#
#
#
#
x$time <- with(x, ave(rep(1, nrow(x)), L1, L2, FUN = seq_along))
#
dcast(x, L2 ~ time, value.var="value", fun.aggregate=mean)
# L2 1 2 3
# 1 a 3.5 4.5 5.5
# 2 b 5.5 6.5 7.5
Here's the approach in the R base:
x <- unlist(mylist)
c(by(x, names(x), mean))
# a1 a2 a3 b1 b2 b3
# 3.5 4.5 5.5 5.5 6.5 7.5
source
share