Skip to content
Prev 256389 / 398506 Next

howto calculate column means in data frame

Hi Jim,

Using ?lapply with ?colMeans should do the trick.  Here is a little sample:

eg <- list(mtcars, mtcars) # mtcars data frame twice in a list
resultsmean <- lapply(eg, colMeans) # calculate column means for each
element of "eg"
resultsmean # show the results

Hope this helps,

Josh
On Sun, Apr 10, 2011 at 8:27 AM, Maas James Dr (MED) <J.Maas at uea.ac.uk> wrote: