[R] row mean

arun smartpink111 at yahoo.com
Wed May 28 10:22:56 CEST 2014


Hi Eliza,
No problem.
You can also do:
lst1 <- vector("list",12)
for(i in seq_along(lst1)) lst1[[i]] <- colMeans(AAA[seq(i,nrow(AAA), by=12),])
A.K.





On Wednesday, May 28, 2014 4:17 AM, eliza botto <eliza_botto at hotmail.com> wrote:



Thankyou very much dennis and arun,


The codes worked as ever.

:D

Eliza


> Date: Tue, 27 May 2014 18:43:44 -0700
> From: smartpink111 at yahoo.com
> Subject: Re: [R] row mean
> To: r-help at r-project.org
> CC: eliza_botto at hotmail.com
> 
> 
> 
> 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