[R] row mean

arun smartpink111 at yahoo.com
Wed May 28 03:43:44 CEST 2014



Forgot, about the mean:
lapply(split(seq_len(nrow(AAA)),((seq_len(nrow(AAA))-1)%%12)+1),function(i) colMeans(AAA[i,]))
A.K.


On , arun <smartpink111 at yahoo.com> wrote:


Hi Eliza,
May be this helps:
lapply(split(seq_len(nrow(AAA)),((seq_len(nrow(AAA))-1)%%12)+1),function(i) AAA[i,])
A.K.





On Tuesday, May 27, 2014 6:48 PM, eliza botto <eliza_botto at hotmail.com> wrote:
Dear R family,
I have this matrix say
AAA<-matrix(sample(1:240),ncol=2)
I first want to combine every 13th row in both columns. precisely, starting from row-1 1,13,25,37,49,.... then starting from row-2 
2,14,26,38,50 also 3,15,27,39,51 and similarly starting from row 4, row number 5, row 6... till 12th row,for both columns. so in a way 
we will have list of 12 matrices each with 10 rows and 2 columns. 
Finally, I want to calculate mean of each column of each matrix in that list, while keeping the integrity of the list intact. 
Kindly Advice!

Thankyou very much indeed in advance.
Eliza 

                          
    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list