[R] how to divide each column in a matrix by its colSums?

casperyc casperyc at hotmail.co.uk
Sun Nov 28 21:46:32 CET 2010


Hi,

I have a matrix, say 
m=matrix(c(
	983,679,134,
	383,416,84,
	2892,2625,570
	),nrow=3
)

i can find its row/col sum by

rowSums(m)
colSums(m)

How do I divide each row/column by its rowSum/colSums and still return in
the matrix form?
(i.e. the new rowSums/colSums =1)

Thanks.

Casper

-- 
View this message in context: http://r.789695.n4.nabble.com/how-to-divide-each-column-in-a-matrix-by-its-colSums-tp3062739p3062739.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list