As a follow up is there any way to also get the count for each combination?
For example
y A B C
0 1 1 2
0 1 2 1
1 1 1 2
0 1 1 2
1 1 1 2
1 1 2 1
0 1 2 2
Should become:
y A B C count
2 1 1 2 4
1 1 2 1 2
0 1 2 2 1
.
.
.
So I would know there were 2 successes out of 4.
Thanks!
Chris
On Fri, Jul 20, 2012 at 10:41 AM, Christopher Desjardins <
cddesjardins at gmail.com> wrote:
Thanks the aggregate() command is what I was looking for.
Chris
On Thu, Jul 19, 2012 at 9:03 PM, David L Carlson <dcarlson at tamu.edu>wrote:
dtf <- read.table(text="y A B C
+ 0 1 1 2
+ 0 1 2 1
+ 1 1 1 2
+ 0 1 1 2
+ 1 1 1 2
+ 1 1 2 1
+ 0 1 2 2",
+ header=TRUE)
dtagroup <- aggregate(y~A+B+C, dtf, sum)
# Gets you the groups. If you need the column/row order:
dtagroup <- dtagroup[order(dtagroup$y, decreasing=TRUE),c(4, 1:3)]
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
project.org] On Behalf Of Christopher Desjardins
Sent: Thursday, July 19, 2012 7:35 PM
To: R help
Subject: [R] Changing ungrouped cases to grouped cases
Hi,
I have my data the following way:
y A B C
0 1 1 2
0 1 2 1
1 1 1 2
0 1 1 2
1 1 1 2
1 1 2 1
0 1 2 2
.
.
.
And so on. How can I make my data look like the following:
y A B C
2 1 1 2
1 1 2 1
0 1 2 2
.
.
.
In other words how can I change my ungrouped cases into grouped cases?
Thanks!
Chris
[[alternative HTML version deleted]]