hello all, I have a dataset where the subjects are duplicated. How do I subset such that I can get only I row/subject. aa<-c(1,1,2,2,3,3,4,4,5,5,6,6) bb<-c(56,56,33,33,53,53,20,20,63,63,9,9) cc<-data.frame(aa,bb) I would like to subset df(cc) such that I can get aa bb 1 56 2 33 3 53 4 20 5 63 6 9 I know this should be fairly easy but I can't figure how to do it in a dataframe and keep all my columns Thanks
if you want the first row for the unique 'aa' entries, try the
following:
cc[!duplicated(cc$aa), ]
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
Quoting Lanre Okusanya <lanre.okusanya at gmail.com>:
> hello all,
>
> I have a dataset where the subjects are duplicated. How do I subset
> such that I can get only I row/subject.
>
> aa<-c(1,1,2,2,3,3,4,4,5,5,6,6)
> bb<-c(56,56,33,33,53,53,20,20,63,63,9,9)
> cc<-data.frame(aa,bb)
>
> I would like to subset df(cc) such that I can get
> aa bb
> 1 56
> 2 33
> 3 53
> 4 20
> 5 63
> 6 9
>
> I know this should be fairly easy but I can't figure how to do it in a
> dataframe and keep all my columns
>
> Thanks
>
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
>
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
> cc[!duplicated(cc$bb),]aa bb 1 1 56 3 2 33 5 3 53 7 4 20 9 5 63 11 6 9>On 8/9/06, Lanre Okusanya <lanre.okusanya@gmail.com> wrote:> > hello all, > > I have a dataset where the subjects are duplicated. How do I subset > such that I can get only I row/subject. > > aa<-c(1,1,2,2,3,3,4,4,5,5,6,6) > bb<-c(56,56,33,33,53,53,20,20,63,63,9,9) > cc<-data.frame(aa,bb) > > I would like to subset df(cc) such that I can get > aa bb > 1 56 > 2 33 > 3 53 > 4 20 > 5 63 > 6 9 > > I know this should be fairly easy but I can't figure how to do it in a > dataframe and keep all my columns > > Thanks > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]]
Thanks. I tried that, however for some reason, it still left some duplicates On 8/9/06, Gary Collins <collins.gs at gmail.com> wrote:> try > > > unique(cc) > aa bb > 1 1 56 > 3 2 33 > 5 3 53 > 7 4 20 > 9 5 63 > 11 6 9 > > HTH > > Gary > > On 09/08/06, Lanre Okusanya <lanre.okusanya at gmail.com> wrote: > > hello all, > > > > I have a dataset where the subjects are duplicated. How do I subset > > such that I can get only I row/subject. > > > > aa<-c(1,1,2,2,3,3,4,4,5,5,6,6) > > bb<-c(56,56,33,33,53,53,20,20,63,63,9,9) > > cc<-data.frame(aa,bb) > > > > I would like to subset df(cc) such that I can get > > aa bb > > 1 56 > > 2 33 > > 3 53 > > 4 20 > > 5 63 > > 6 9 > > > > I know this should be fairly easy but I can't figure how to do it in a > > dataframe and keep all my columns > > > > Thanks > > > > ______________________________________________ > > R-help at 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 > > and provide commented, minimal, self-contained, reproducible code. > > >