Re: [R] conditional selection with Factors

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Wed 06 Apr 2005 - 21:48:13 EST


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@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@precheza.cz



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 21:54:42 2005

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