[R] conditional selection with Factors

From: H J Gerber <Gerbehj_at_unisa.ac.za>
Date: Wed 06 Apr 2005 - 19:34:07 EST


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
> 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@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 Received on Wed Apr 06 19:38:52 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:02 EST