[R] Deleting observations from baseline that don't appear in follow up

Sarah Goslee sarah.goslee at gmail.com
Fri Apr 27 22:47:21 CEST 2012


What about

baseline[baseline$id %in% follow.up$id, ]

or the same thing but using subset().

Sarah

On Fri, Apr 27, 2012 at 4:36 PM, justin jarvis
<littledude.jarvis at gmail.com> wrote:
> Hello all,
> I'm almost embarrassed to post this , it seems so easy.  Suppose I have a
> baseline and follow up survey but some people are missing in the follow up:
>
>> baseline<-data.frame(id=c(3,5,7,9,12), data= runif(5))
>> follow.up<-data.frame(id=c(3,7,9,12), data= runif(4))
>> baseline
>  id       data
> 1 3 0.66771988
> 2  5 0.28794744
> 3  7 0.01892821
> 4  9 0.64863175
> 5 12 0.86485882
>> follow.up
>  id      data
> 1  3 0.8237210
> 2 7 0.8140544
> 3  9 0.8803674
> 4 12 0.8031520
>
> Here, in follow up we are missing person #5.  I need to delete him from the
> baseline, so that I have an equal number of rows once again.  Obviously
>
> baseline<-baseline[-2,] won't cut it here, since in my data set I have
> thousands of people.
>
> Thanks in advance
>
> Justin

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list