[R] R does not subset

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Fri May 3 15:16:08 CEST 2013


This typically occurs because of sloppy manual data entry outside of R. To relieve further analysis pain, you can manually clean the data (usually only effective for one-time analyses) or use R to fix problems right after loading the data (there are multiple methods for doing this... I prefer using ?sub on character data before creating the factor).
---------------------------------------------------------------------------
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.

Mihai Nica <mihainica at yahoo.com> wrote:

>Hi:
>
>"(note the space after "Infected")"
>
>Since I lost a morning too with this issue, I am just curious, why is
>there a space?�
>
>I know, it must be a dumb question, a reasonable programming rule, but
>that's my level :-)
>>mike
>
>
>>________________________________
>> From: Jorge I Velez <jorgeivanvelez at gmail.com>
>>To:Katarzyna Kulma <katarzyna.kulma at gmail.com> 
>>Cc: R mailing list <r-help at r-project.org> 
>>Sent: Friday, May 3, 2013 6:01 AM
>>Subject: Re: [R] R does not subset
>> 
>>
>>Hi Kasia,
>>
>>You need
>>
>>subset(REC2,� INFECTION=="Infected ")
>>
>>(note the space after "Infected").
>>
>>HTH,
>>Jorge.-
>>
>>
>>On Fri, May 3, 2013 at 7:48 PM, Katarzyna Kulma
>><katarzyna.kulma at gmail.com>wrote:
>>
>>> Hi everyone,
>>>
>>> I know there have been several requests regarding subsetting before,
>but
>>> none of them really helps with my problem:
>>>
>>> I'm trying to subset only infected individuals from the REC2
>data.frame:
>>>
>>> > str(REC2)
>>> 'data.frame':� � 362 obs. of� 7 variables:
>>>� $ RINGNO�  : Factor w/ 370 levels "BL17546","BL17577",..: 78 81 67
>41 58
>>> 66 17
>>>� $ year� �  : Factor w/ 8 levels "Y2002","Y2003",..: 1 2 1 2 1 1 2 1
>1 3
>>> ...
>>>� $ ccFLEDGE : int� 6 6 6 5 6 7 6 7 6 5 ...
>>>� $ rec2012� : int� 2 1 2 2 1 2 1 1 1 0 ...
>>>� $ binage� : Factor w/ 2 levels "ad","juv": 1 2 1 1 1 1 1 1 1 1 ...
>>>� $ INFECTION: Factor w/ 2 levels "Infected ","Uninfected ": 2 1 2 1
>2 2 1 2
>>> 2 1 ...
>>>� $ all.rsLD : num� -4.62 -6.19 -3.62 -4.19 -2.62 ...
>>>
>>> using either
>>>
>>> RECinf<-REC2[which (REC2$INFECTION=="Infected"),]
>>>
>>> or
>>>
>>> RECinf<-subset(REC2,� INFECTION=="Infected")
>>>
>>> in both cases I get empty data frame (0 observations):
>>>
>>> > str(RECinf)
>>> 'data.frame':� � 0 obs. of� 7 variables:
>>>� $ RINGNO�  : Factor w/ 370 levels "BL17546","BL17577",..:
>>>� $ year� �  : Factor w/ 8 levels "Y2002","Y2003",..:
>>>� $ ccFLEDGE : int
>>>� $ rec2012� : int
>>>� $ binage� : Factor w/ 2 levels "ad","juv":
>>>� $ INFECTION: Factor w/ 2 levels "Infected ","Uninfected ":
>>>� $ all.rsLD : num
>>>
>>> When subsetting, R doesn't return any warning or error message.
>Besides, I
>>> used same codes many times beforeand they worked perfectly well. Any
>ideas
>>> why this case is different?
>>>
>>> Thanks for your help,
>>> Kasia
>>>
>>>� � � �  [[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.
>>
>>
>>
>	[[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.



More information about the R-help mailing list