[R] Fast Normalize by Group

Noah Silverman noahsilverman at ucla.edu
Thu Nov 29 19:55:08 CET 2012


Hi,

I have a very large data set (aprox. 100,000 rows.)

The data comes from around 10,000 "groups" with about 10 entered per group.

The values are in one column, the group ID is an integer in the second column.

I want to normalize the values by group:

for(g in unique(groups){
	x[group==g] / sum(x[group==g])
}

This works find in a loop, but is slow.  Is there a faster way to do this?

Thanks!


More information about the R-help mailing list