[R] pulling out pairs from data frame

Bert Gunter gunter.berton at gene.com
Tue Aug 13 18:05:28 CEST 2013


?duplicated

yourframe[!duplicated(yourframe)$Individual,]

-- Bert

On Tue, Aug 13, 2013 at 8:12 AM, Kripa R <kripa777 at 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: smartpink111 at yahoo.com
>> Subject: Re: [R] pulling out pairs from data frame
>> To: kripa777 at hotmail.com
>> CC: r-help at 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 <kripa777 at hotmail.com>
>> To: arun <smartpink111 at yahoo.com>
>> Cc: R help <r-help at 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: smartpink111 at yahoo.com
>> > Subject: Re: [R] pulling out pairs from data frame
>> > To: kripa777 at hotmail.com
>> > CC: r-help at 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 <kripa777 at hotmail.com>
>> > To: "r-help at r-project.org" <r-help at 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 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.
>> >
>
>         [[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.
>



-- 

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



More information about the R-help mailing list