Re: [R] newbie question: ROW average

From: Rolf Turner <>
Date: Mon 29 May 2006 - 21:55:50 EST

Dimitris Rizopoulos wrote:

> look at ?rowMeans; you can also use "apply(mat, 1, mean)" but
> rowMeans() is better.

	By my reading of the question, this is not what
	Ezhil wants.  He said:

	``I have a 992 x 74 matrix. I would like to form a new matrix
	  by averaging each 4 rows from the original one.''

	I.e. he wants (I think) the first row of the new matrix
	to be the mean of the first 4 rows of the old one, the
	second row of the new matrix to be the mean of rows 5
	through 8 of the old one, and so on.

	One way this could be done is via

	> <- t(apply(array(t(m.old),dim=c(74,4,992/4)),c(1,3),mean))


				Rolf Turner

______________________________________________ mailing list PLEASE do read the posting guide! Received on Mon May 29 22:14:13 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 30 May 2006 - 00:10:24 EST.

Mailing list information is available at Please read the posting guide before posting to the list.