Quantcast

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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

justin jarvis
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

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Deleting observations from baseline that don't appear in follow up

Sarah Goslee
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
<[hidden email]> 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Deleting observations from baseline that don't appear in follow up

Jeff Newmiller
In reply to this post by justin jarvis
Read ?merge
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.

justin jarvis <[hidden email]> 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
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.
Loading...