[R] factors and ops
Petr Pikal
petr.pikal at precheza.cz
Fri May 26 08:54:39 CEST 2006
Hi
On 26 May 2006 at 1:33, Erin Hodgess wrote:
Date sent: Fri, 26 May 2006 01:33:34 -0500
From: Erin Hodgess <hodgess at gator.dt.uh.edu>
To: r-help at stat.math.ethz.ch
Subject: [R] factors and ops
> Dear R People
>
> I have a variable which is an ID number that is a factor.
>
> I would like to look for ID numberbs that are greeater than
> a particular value.
>
> However, factors are a big ugly for these operations.
>
> I was messing with the HR data set from the SASmixed package.
>
> HR$Patient is a factor like that.
>
> Now if I used:
> subset(HR,as.integer(as.character(Patient)) > 214)
>
> that will work.
AFAIK no other way. If you know you do not want HR$Patient as factor
you can use
HR$Patient <- as.integer(as.character(HR$Patient))
or
HR$Patient <- as.numeric(as.character(HR$Patient))
and then
subset(HR,Patient > 214)
but beware of attaching data.frame as if it is attached you need to
detach it first and than to change factor to numeric and only then to
attach it again.
HTH
Petr
>
> If seems to me that there may be a better way.
> Is that true?
>
> R Version 2.3.0 Windows
>
> Thanks in advance!
>
>
> sincerely,
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: hodgess at gator.uhd.edu
>
> ______________________________________________
> 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