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
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
Wantia [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: [R] get mean of several rows
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
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