Yes, you're right. So I guess you should match on duplicated values, something like (untested)
with(dat1, dat1[individual %in% individual[duplicated(individual)],] which is presumably essentially what you gave. -- Bert On Tue, Aug 13, 2013 at 10:41 AM, arun <smartpink...@yahoo.com> wrote: > Bert, > > dat1<-structure(list(SameName = 1:6, Individual = c(4L, 15L, 1L, 15L, > 2L, 4L), Age = c(80L, 56L, 75L, 56L, 58L, 80L), Gender = c("M", > "F", "F", "F", "F", "M")), .Names = c("SameName", "Individual", > "Age", "Gender"), class = "data.frame", row.names = c(NA, -6L > )) > Your solution gives: > > dat1[!duplicated(dat1$Individual),] > # SameName Individual Age Gender > #1 1 4 80 M > #2 2 15 56 F > #3 3 1 75 F > #5 5 2 58 F > > The OP asked for: > And I want to pull out paired samples, so the resulting file would look > something like this: >>>> SampleName Individual Age Gender > #>>> 1 4 80 M >>>> 2 15 56 F >>>> 4 15 56 F >>>> 6 4 80 M > > Anyway, the question was not clear as I mentioned in the earlier mail. > Regards, > A.K. > > > > > ----- Original Message ----- > From: Bert Gunter <gunter.ber...@gene.com> > To: Kripa R <kripa...@hotmail.com> > Cc: arun <smartpink...@yahoo.com>; R help <r-help@r-project.org> > Sent: Tuesday, August 13, 2013 12:09 PM > Subject: Re: [R] pulling out pairs from data frame > > Sorry. Typo. Corrected version is: > > yourframe[!duplicated(yourframe$Individual),] > > -- Bert > > On Tue, Aug 13, 2013 at 9:05 AM, Bert Gunter <bgun...@gene.com> wrote: >> ?duplicated >> >> yourframe[!duplicated(yourframe)$Individual,] >> >> -- Bert >> >> On Tue, Aug 13, 2013 at 8:12 AM, Kripa R <kripa...@hotmail.com> wrote: >>> I manipulated the code you sent and it works perfectly, thanks! >>> >>> .kripa >>> >>>> Date: Tue, 13 Aug 2013 08:10:53 -0700 >>>> From: smartpink...@yahoo.com >>>> Subject: Re: [R] pulling out pairs from data frame >>>> To: kripa...@hotmail.com >>>> CC: r-help@r-project.org >>>> >>>> >>>> >>>> Hi, >>>> The conditions are still not clear. >>>> >>>> >>>> dat2<- dat1[dat1$Individual%in% reps,] >>>> dat2 >>>> # SameName Individual Age Gender >>>> #1 1 4 80 M >>>> #2 2 15 56 F >>>> #4 4 15 56 F >>>> #6 6 4 80 M >>>> A.K. >>>> >>>> ________________________________ >>>> From: Kripa R <kripa...@hotmail.com> >>>> To: arun <smartpink...@yahoo.com> >>>> Cc: R help <r-help@r-project.org> >>>> Sent: Tuesday, August 13, 2013 10:56 AM >>>> Subject: RE: [R] pulling out pairs from data frame >>>> >>>> >>>> >>>> >>>> Oops! Ok So I have this file: >>>> >>>> SampleName Individual Age Gender >>>> 1 4 80 M >>>> 2 15 56 F >>>> 3 1 75 F >>>> 4 15 56 F >>>> 5 2 58 F >>>> 6 4 80 M >>>> >>>> And I want to pull out paired samples, so the resulting file would look >>>> something like this: >>>> SampleName Individual Age Gender >>>> 1 4 80 M >>>> 2 15 56 F >>>> 4 15 56 F >>>> 6 4 80 M >>>> >>>> .kripa >>>> >>>> >>>> > Date: Mon, 12 Aug 2013 18:36:08 -0700 >>>> > From: smartpink...@yahoo.com >>>> > Subject: Re: [R] pulling out pairs from data frame >>>> > To: kripa...@hotmail.com >>>> > CC: r-help@r-project.org >>>> > >>>> > Hi, >>>> > The question is not clear so not sure this is what you wanted. >>>> > >>>> > dat1<- read.table(text=" >>>> > SameName áIndividual áAge Gender >>>> > 1 4 á80 áM á >>>> > 2 15 á56 F >>>> > 3 1 75 áF >>>> > 4 15 á56 áF >>>> > 5 á2 á58 áF >>>> > 6 4 á80 áM >>>> > ",sep="",header=TRUE,stringsAsFactors=FALSE) >>>> > reps<-c(4,15)á >>>> > >>>> > ádat1$Newcol<-as.numeric(dat1$Individual%in% reps) >>>> > ádat1 >>>> > # áSameName Individual Age Gender Newcol >>>> > #1 á á á á1 á á á á á4 á80 á á áM á á á1 >>>> > #2 á á á á2 á á á á 15 á56 á á áF á á á1 >>>> > #3 á á á á3 á á á á á1 á75 á á áF á á á0 >>>> > #4 á á á á4 á á á á 15 á56 á á áF á á á1 >>>> > #5 á á á á5 á á á á á2 á58 á á áF á á á0 >>>> > #6 á á á á6 á á á á á4 á80 á á áM á á á1 >>>> > A.K.á >>>> > >>>> > >>>> > >>>> > >>>> > ----- Original Message ----- >>>> > From: Kripa R <kripa...@hotmail.com> >>>> > To: "r-help@r-project.org" <r-help@r-project.org> >>>> > Cc: >>>> > Sent: Monday, August 12, 2013 6:59 PM >>>> > Subject: [R] pulling out pairs from data frame >>>> > >>>> > Hello everyone, >>>> > I'm having trouble pulling out paired samples from a data set... I have >>>> > the following: >>>> > >>>> > reps<-c(4,15) #the variable reps is a list of all paired samples >>>> > >data >>>> > >>>> > >>>> > >>>> > >>>> > >>>> > á >>>> > á SameName >>>> > á >>>> > á >>>> > á Individual >>>> > á >>>> > á >>>> > á Age >>>> > á >>>> > á >>>> > á Gender >>>> > á >>>> > >>>> > >>>> > á >>>> > á 1 >>>> > á >>>> > á >>>> > á 4 >>>> > á >>>> > á >>>> > á 80 >>>> > á >>>> > á >>>> > á M >>>> > á >>>> > >>>> > >>>> > á >>>> > á 2 >>>> > á >>>> > á >>>> > á 15 >>>> > á >>>> > á >>>> > á 56 >>>> > á >>>> > á >>>> > á F >>>> > á >>>> > >>>> > >>>> > á >>>> > á 3 >>>> > á >>>> > á >>>> > á 1 >>>> > á >>>> > á >>>> > á 75 >>>> > á >>>> > á >>>> > á F >>>> > á >>>> > >>>> > >>>> > á >>>> > á 4 >>>> > á >>>> > á >>>> > á 15 >>>> > á >>>> > á >>>> > á 56 >>>> > á >>>> > á >>>> > á F >>>> > á >>>> > >>>> > >>>> > á >>>> > á 5 >>>> > á >>>> > á >>>> > á 2 >>>> > á >>>> > á >>>> > á 58 >>>> > á >>>> > á >>>> > á F >>>> > á >>>> > >>>> > >>>> > á >>>> > á 6 >>>> > á >>>> > á >>>> > á 4 >>>> > á >>>> > á >>>> > á 80 >>>> > á >>>> > á >>>> > á M >>>> > á >>>> > >>>> > >>>> > >>>> > >>>> > I'd like to make a new variable with only the samples that have pairs. >>>> > Any suggestions would be greatly appreciated >>>> > >>>> > Thanks! >>>> > >>>> > >>>> > >>>> > >>>> > >>>> > .kripa >>>> > ááá ááá ááá á ááá ááá á >>>> > ááá [[alternative HTML version deleted]] >>>> > >>>> > ______________________________________________ >>>> > R-help@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. >>>> > >>> >>> [[alternative HTML version deleted]] >>> >>> >>> ______________________________________________ >>> R-help@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. >>> >> >> >> >> -- >> >> Bert Gunter >> Genentech Nonclinical Biostatistics >> >> Internal Contact Info: >> Phone: 467-7374 >> Website: >> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm ______________________________________________ R-help@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.