[R] R does not subset
Daniel Nordlund
djnordlund at frontier.com
Fri May 3 18:43:39 CEST 2013
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Katarzyna Kulma
> Sent: Friday, May 03, 2013 4:21 AM
> To: David Kulp
> Cc: r-help at r-project.org
> Subject: Re: [R] R does not subset
>
> Jorge, thanks for your suggestions, but they give the same (empty) result:
>
> > RECinf<-subset(REC2, INFECTION=="Infected")
> > head(RECinf)
> [1] RINGNO year ccFLEDGE rec2012 binage INFECTION all.rsLD
> <0 rows> (or 0-length row.names)
>
> but David's suggestion worked! :
>
> > RECinf<-REC2[REC2$INFECTION=="Infected ",]
> > head(RECinf)
> RINGNO year ccFLEDGE rec2012 binage INFECTION all.rsLD
> 2 BX23298 Y2003 6 1 juv Infected -6.1938776
> 4 BT53646 Y2003 5 2 ad Infected -4.1938776
> 7 BT53248 Y2003 6 1 ad Infected -2.1938776
> 11 BY75833 Y2004 5 0 ad Infected -4.6574803
> 13 BX23067 Y2004 6 0 ad Infected -3.6574803
> 17 BX24240 Y2004 6 0 ad Infected 0.3425197
>
>
> still not sure why the subset() function didn't work, though.
>
> Thanks for your help!
>
>
>
Maybe it didn't work because you still didn't have a space at the end of the value you were comparing (apparently the factor was defined with a space). with). Try the following (and notice the space at the end of "Infected ".
RECinf<-subset(REC2, INFECTION=="Infected ")
David's suggestion worked because you did include a space there.
Dan
Daniel Nordlund
Bothell, WA USA
More information about the R-help
mailing list