justin jarvis
2012-Apr-27 20:36 UTC
[R] Deleting observations from baseline that don't appear in follow up
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)) > baselineid data 1 3 0.66771988 2 5 0.28794744 3 7 0.01892821 4 9 0.64863175 5 12 0.86485882> follow.upid 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]]
Sarah Goslee
2012-Apr-27 20:47 UTC
[R] Deleting observations from baseline that don't appear in follow up
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
Jeff Newmiller
2012-Apr-27 20:49 UTC
[R] Deleting observations from baseline that don't appear in follow up
Read ?merge
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> 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 <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
>
> [[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.