Re: [R] combined multiple observations

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 04 May 2006 - 21:20:39 EST

Assuming DF is your data frame, try this:

   aggregate(DF[,0-1:2], DF[,1:2], sum)

On 5/4/06, YIHSU CHEN <yschen@jhu.edu> wrote:
> Dear R users:
>
> I have a data frame as follows, where e1-e3 are indicator variables with value equal 0 or 1.
>
> St County e1 e2 e3
> 1 2 1 0 0
> 1 2 0 1 0
> 2 1 0 0 1
> 2 2 1 0 0
>
> What I would like to do is to combine observations with same pair of "ST" and "County" together. For example, for the St=1 and County=2, I would like to have follows:
>
> St County e1 e2 e3
> 1 2 1 1 0
>
> Since I have a total of more than 30000 observations, any blue force way seems to be not efficient. Does anyone of you have experience to deal with it?
>
> Thank you so much.
>
>
> Yihsu Chen
> The Johns Hopkins University
>
> ______________________________________________
> 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
>



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 Thu May 04 21:29:34 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 05 May 2006 - 00:10:11 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.