[R] get mean of several rows

Jan Wantia wantia at ifi.unizh.ch
Thu Dec 4 14:03:57 CET 2003


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 
the second n rows, etc., so that I get a vector like:

v == mean1(row 1:5), mean2(row6:10),...

(trivial, you might say. I find it rather mind-boggling, though: I tried 
to get the mean from the array before splitting it, after splitting it, 
looping through it with for-loops...I feel like an idiot by now; looks 
like I missed a crucial point of how 'R' works.)

Thanks a lot in advance!
-- 

______________________________________________________

Jan Wantia
Dept. of Information Technology, University of Zürich
Andreasstr. 15
CH 8050 Zürich
Switzerland

Tel.:     +41 (0) 1 635 4315
Fax:     +41 (0) 1 635 45 07
email: wantia at ifi.unizh.ch




More information about the R-help mailing list