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 Thanks in advance Paul Green
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> dfX1 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
Have you considered "table"? spencer graves 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 > > Thanks in advance > > Paul Green > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help