[R] r equivalent of egen? Not tapply

Tobias Muhlhofer t.muhlhofer at lse.ac.uk
Sun Jun 26 12:33:05 CEST 2005


Thomas,

I usually use the aggregate() function, proceeding as follows.

Construct a vector of 1s that is the same length as your entire data.

Then use aggregate() with sum as a function on this vector and your 
grouping variable as a by argument (note the use of na.rm in sum). This 
will create a data.frame with the counts and the panel markers that 
represent the subcategories (one row for each).

Then use merge() to put these back into your original data.frame, as 
this will create the necessary duplicates.

Toby




More information about the R-help mailing list