[R] Fastest Way to Divide Elements of Row With Its RowSum

Gundala Viswanath gundalav at gmail.com
Thu Sep 17 07:40:22 CEST 2009


I have a data frame (dat). What I want to do is for each row,
divide each row  with the sum of its row.

The number of row can be large > 1million.
Is there a faster way than doing it this way?

datnorm;
for (rw in 1:length(dat)) {
    tmp <- dat[rw,]/sum(dat[rw,])
    datnorm <- rbind(datnorm, tmp);
}


- G.V.




More information about the R-help mailing list