[R] Summarizing a matrix

Özgür Asar oasar at metu.edu.tr
Tue Jun 5 10:53:28 CEST 2012


Hi,

x<-matrix(0,80,ncol=1)

will create x matrix with all elements 0 (to be filled by the sums that you
need)

sum(y[y[,4]==1,5]) 

will calculate the sum of 5th column of y with 4th column=1

Similarly, 

sum(y[y[,4]==80,5])

 will calculate the sum of 5th column of y with 4th column=80.

You can adapt this to your case, with simple loops, etc.

Hope this helps.
Ozgur

--
View this message in context: http://r.789695.n4.nabble.com/Summarizing-a-matrix-tp4632319p4632381.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list