[R] newbie question: ROW average

Gabor Grothendieck ggrothendieck at gmail.com
Mon May 29 14:20:37 CEST 2006


Try this:

   rowsum(mat, gl(nrow(mat)/4, 4)) / 4

On 5/29/06, A Ezhil <ezhil02 at yahoo.com> wrote:
> 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?
>
> Thanks in advance.
>
> regards,
> ezhil
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



More information about the R-help mailing list