[R] Grouping and/or splitting

Weidong Gu anopheles123 at gmail.com
Wed Apr 4 02:12:54 CEST 2012


how about

split(inpfil, paste(inpfil[,1],inpfil[,2],sep=','))

Weidong Gu

On Tue, Apr 3, 2012 at 6:42 PM, Ashish Agarwal
<ashish.agarwala at gmail.com> wrote:
> I have a dataframe imported from csv file below:
>
> Houseid,Personid,Tripid,taz
> 1,1,1,4
> 1,1,2,7
> 2,1,1,96
> 2,1,2,4
> 2,1,3,2
> 2,2,1,58
>
> There are three groups identified based on the combination of first and
> second columns. How do I split this data frame?
>
> I tried
> aa <- split(inpfil, inpfil[,1:2])
> but it has problems.
>
> Output desired is
>
> aa[1]
>  Houseid,Personid,Tripid,taz
> 1,1,1,4
> 1,1,2,7
> aa[2]
>  Houseid,Personid,Tripid,taz
> 2,1,1,96
> 2,1,2,4
> 2,1,3,2
> aa[3]
>  Houseid,Personid,Tripid,taz
> 2,2,1,58
>
>        [[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