[R] recoding variables

Roger D. Peng rpeng at jhsph.edu
Thu Mar 11 16:19:39 CET 2004


Basically, you want to use cut().  For example,

x <- 1:20
cut(x, c(0, 8, 15, 20))

This divides x into a factor with levels (0,8], (8,15], and (15,20].

-roger

Shayna Strom wrote:
> Hi,
> 
> I was hoping someone could help me.  I am a graduate student new to using R, and I'm trying to figure out how to recode a continuous variable to make it into an ordinal variable with 3 categories.  I literally have no idea how to proceed--could anyone possibly advise me?  Please copy me on any responses, as I have just subscribed to the R-help email list but don't know whether the subscription has gone through yet.
> 
> Thanks so much-
> Shayna
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list