[R] division of col by the sum of the col

Rolf Turner r.turner at auckland.ac.nz
Tue Sep 23 23:30:04 CEST 2014


On 24/09/14 03:10, carol white wrote:
> Hi, If I want to divide the column of a matrix by the sum of the
> column, should I loop over the columns or can I use apply family?

m1 <- apply(m,2,function(x){x/sum(x)})

should do what you want IIUYC.

cheers,

Rolf Turner

-- 
Rolf Turner
Technical Editor ANZJS



More information about the R-help mailing list