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. 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
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.htmlPetr Pikal petr.pikal at precheza.cz
Try an ordered factor: subset(HR, ordered(Patient) > 214) or HR$Patient <- ordered(HR$Patient) subset(HR, Patient > 214) You might also check that it orders them in the way you want. ordered(HR$Patient) in the first case or just HR$Patient in the second case will display the data followed by the ordering. On 5/26/06, Erin Hodgess <hodgess at gator.dt.uh.edu> wrote:> 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. > > 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 >