Message-ID: <Pine.A41.4.44.0309041046210.61662-100000@homer37.u.washington.edu>
Date: 2003-09-04T17:47:09Z
From: Thomas Lumley
Subject: counts for grouped data
In-Reply-To: <5.1.0.14.2.20030904131820.00b11e98@mailkardia.sph.umich.edu>
On Thu, 4 Sep 2003, Paul Green wrote:
> How does one get counts for grouped data
> from ungrouped data. For example, how can
> I get
>
> X1 X2 Count
> 1 1 1
> 1 2 2
> 2 1 1
> 2 2 1
>
> from
>
> X1 X2
> A A
> A B
> B B
> A B
> B A
>
One possibility is
> df
X1 X2
1 A A
2 A B
3 B B
4 A B
5 B A
> aggregate(rep(1,nrow(df)), df, NROW)
X1 X2 x
1 A A 1
2 B A 1
3 A B 2
4 B B 1
-thomas