[R] means by column after split
S.McClatchie
s.mcclatchie at niwa.cri.nz
Tue Feb 20 00:15:31 CET 2001
Colleagues
----------------------------------
System info:
R version rw1020 on NT
ESS using emacs ver. 20.4
----------------------------------
I need to get the means for each column of a dataframe in the list
created by splitting a data frame. At present, I am getting the mean of all
columns in aggregate.
The structure of the unsplit data is:
> shuttle.tr1[1:10,]
juliandate lat temp.degC
24892 305.9581 -43.18243 11.90729
24893 305.9581 -43.18258 11.90854
24894 305.9582 -43.18272 11.94356
24895 305.9582 -43.18286 11.95356
24896 305.9583 -43.18300 11.95544
24897 305.9583 -43.18315 11.97670
24898 305.9584 -43.18329 11.99171
24899 305.9584 -43.18343 11.99546
24900 305.9585 -43.18358 11.98546
24901 305.9585 -43.18372 11.98858
Now I split the data into 8 groups:
> fine <- 8
> fsh <- factor(cut(shuttle.tr1$juliandate, fine))
> b.shuttle.tr1 <- split.data.frame(shuttle.tr1, fsh)
Here's where i need help, in getting the mean by columns:
> b.shuttle.tr1 <- data.frame(sapply(b.shuttle.tr1, mean))
> b.shuttle.tr1
sapply.b.shuttle.tr1..mean.
(305.96,306.02] 91.51870
(306.02,306.09] 91.41042
(306.09,306.16] 91.12872
(306.16,306.23] 90.15020
(306.23,306.29] 89.94670
(306.29,306.36] 89.91251
(306.36,306.43] 89.83651
(306.43,306.5] 90.00933
>
Help will be appreciated.
Thanks
Sam
Sam McClatchie, Research scientist (fisheries acoustics))))))))))
NIWA (National Institute of Water & Atmospheric Research Ltd)
PO Box 14 901, Kilbirnie, Wellington, New Zealand
s.mcclatchie at niwa.cri.nz
/\
...>><xX(°> // \\
/// \\\
//// \\\\
/// <°)Xx><<
///// \\\\\\
><(((°>
>><(((°> ...>><xX(°>O<°)Xx><<
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list