[R] Changing ungrouped cases to grouped cases
David L Carlson
dcarlson at tamu.edu
Fri Jul 20 04:03:40 CEST 2012
> 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]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list