The dataset
firstList <- list(a = 1:3, b = 4:6)
secondList <- list(c = 7:9, d = 10:12)
I am trying to calculate the mean of multiple lists with mapply.
mapply(mean, firstList, secondList)
It did not work because mean
only averages its first argument as per
Using mapply with mean function on a matrix
This works correctly:
mapply(mean, firstList)
mapply(mean, secondList)
I then tried lapply
to supply one list at a time to mapply
lapply(c(firstList, secondList), function(x) mapply(mean, x))
The output was NOT the mean but the individual lists
What I need is how to calculate the mean
of multiple list using mapply
. I also would appreciate an explanation as of why mapply
did not return the lists `mean'
Many thanks in advance