Re: [R] r equivalent of egen? Not tapply

From: Tobias Muhlhofer <t.muhlhofer_at_lse.ac.uk>
Date: Sun 26 Jun 2005 - 20:33:05 EST


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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Jun 26 21:47:36 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:02 EST