[R] conditional selection with Factors

Petr Pikal petr.pikal at precheza.cz
Wed Apr 6 13:48:13 CEST 2005


Hi

On 6 Apr 2005 at 11:34, H J Gerber wrote:

> Hi All,
> 
> I want to select a level of a factor variable from a dataset. I have
> the folowing data: dataset: use factor: month (use$month,
> levels=February, July) > use[1:5,]
>      month registration use  department size
> 1 February     KKG151GP   Y      Safety  1.6
> To select February I tried:
> > use[use$month=="February"]
> Error in "[.data.frame"(use, use$month == "February") : 
>         undefined columns selected

Dimensions!
use[use$month=="February",]

shall show all columns where use$month = February

Cheers
Petr

> > use[use$month == levels(use$month)[1]]
> Error in "[.data.frame"(use, use$month == levels(use$month)[1]) : 
>         undefined columns selected
> It seems if a logical variable is created, and the subsetting on a
> factor variable won't work directly.(It works directly for numeric
> variables)  Can anyone help please.
> 
> Regards
> Hennie Gerber
> 
> 
> Hennie Gerber
> Statistician
> UNISA - Research Support
> + 27 12 429 3188
> Waarskuwing!
> Die sienings uitgespreek is my eie en nie noodwendig my werkgewer sin
> nie Warning! All views expressed are my own and not necessarily that
> of my employer.
> 
> 
> 
> 
> 
> 
> ----------------------------------------------------------------------
> ----- This message (and attachments) is subject to restrictions and a
> disclaimer. Please refer to http://www.unisa.ac.za/disclaimer for full
> details.
> ----------------------------------------------------------------------
> ----- <<<<gwavasig>>>> <<<< gwavasig >>>>
>  [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list