[R] newbie question: ROW average
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Mon May 29 13:44:50 CEST 2006
A Ezhil <ezhil02 at yahoo.com> writes:
> Hi,
>
> I am new to R programming. I have a 992 x 74 matrix. I
> would like to form a new matrix by averging each 4
> rows
> from the original one. How can I use 'apply' instead
> of usual mean inside the nested for loop?
How about
dim(M) <- c(4,248,74)
mn <- apply(M, c(2,3), mean)
(Yes, this is a bit confusing and easy to get wrong...)
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list