[R] how to recode in my dataset?

Dimitrios Rizopoulos Dimitris.Rizopoulos at med.kuleuven.be
Sun Jul 2 20:02:52 CEST 2006


probably ?cut() is what you're looking for, e.g., something like:

ind <- cut(mydata$soiltem, seq(0, 60, 0.2), labels = FALSE)
seq(0.1, 60, 0.2)[ind]


I hope it helps.

Best,
Dimitris

---- 
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting zhijie zhang <epistat at gmail.com>:

> Dear Rusers,
>  My question is about "recode variables". First, i'd like to say
> something about the idea of recoding:
>  My dataset have three variables:type,soiltem and airtem,which means
> grass type, soil temperature and air temperature. As we all known,
> the
> change of air temperature is greater than soil temperature,so the
> values in those two different temperaturemay represent different
> range.
>  My recoding is to recode soiltem with 0.2 intervals, and airtem
> with
> 0.5 intervals, that is:
> In soiltem:0~0.2<-0.1,  0.2~0.4<-0.3, 0.4`0.6<-0.5,...etc;
> In airtem:0~0.5<-0.25,  0.5~1<-0.75, 1`1.5<-1.25,...etc;
> My example like this:
> type<-c(1, 1, 2, 3,4,1,1,4,3,2)
> soiltem<-c(19.2,18.6,19.5,19.8,19.6,20.6,19.1,18.7,22.4,21.6)
> airtem<-c(19.9,20.5,21.6,25.6,22.6,21.3,23.7,21.5,24.7,24.4)
> mydata<-data.frame(type,soiltem,airtem) #copy the above four
> arguments
> to generate the dataset
> 
> mydata
>    type soiltem airtem
> 1     1    19.2   19.9
> 2     1    18.6   20.5
> 3     2    19.5   21.6
> 4     3    19.8   25.6
> 5     4    19.6   22.6
> 6     1    20.6   21.3
> 7     1    19.1   23.7
> 8     4    18.7   21.5
> 9     3    22.4   24.7
> 10    2    21.6   24.4
> 
> Thanks very much!
> -- 
> Kind Regards,
> Zhi Jie,Zhang ,PHD
> Department of Epidemiology
> School of Public Health
> Fudan University
> Tel:86-21-54237149
> 
> ______________________________________________
> 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
> 
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list