RE: [R] get mean of several rows

2003-12-04 Thread Liaw, Andy
1. Using rowMeans() is more efficient for computing row means. 2. Mean of five rows is the same as mean of the five row means (exception: if you have NAs, and set na.rm=TRUE). So you can just do something like: k - ceiling(nrow(x) / 5) ktimes - if (rem - nrow(x) %% 5) c(rep(5, k-1), rem) else

Re: [R] get mean of several rows

2003-12-04 Thread Thomas Lumley
On Thu, 4 Dec 2003, Jan Wantia wrote: Dear all! After hours of trying around, I gave up: I have a 2-dimensional array, and I know how to split it into its rows and how to get the mean for every row using 'sapply'. But what I want is to calculate the mean over the first n rows, and then

RE: [R] get mean of several rows

2003-12-04 Thread Gabor Grothendieck
The following: c( tapply( x, (row(x)-1)%/%5, mean ) ) gives a vector whose first element is the mean of every element in the rows 1 through 5 inclusive, whose second element is the mean of every element rows 6 through 10 inclusive, etc. --- Date: 4 Dec 2003 14:03:57 +0100 From: Jan

Re: [R] get mean of several rows

2003-12-04 Thread Richard A. O'Keefe
Jan Wantia [EMAIL PROTECTED] asked: I have a 2-dimensional array, and I know how to split it into its rows and how to get the mean for every row using 'sapply'. But what I want is to calculate the mean over the first n rows, and then the second n rows, etc., so