How to change the levels of a variable???
Another way to do this is as follows:
x <- factor(letters)
levels(x) <- list(ab=c('a','b'),cd=c('c','d'))
x
[1] ab ab cd cd e f g h i j k l m n o p q r s t u v w x y [26] z Levels: ab cd e f g h i j k l m n o p q r s t u v w x y z Frank Harrell
John Fox wrote:
At 08:27 AM 21/09/2001 -0300, Ronaldo Reis Jr. wrote:
Hi, I have a simple question. I have a variable with 3 levels. Variable A A A A A A B B B B B B C C C C C C I need to make a new vector renaming de levels B and C for D. NewVariable A A A A A A D D D D D D D D D D D D I dont find how to make it in manuals or in this list. Can anyone help-me??? Thank you Ronaldo --
Dear Ronaldo,
There are several ways to do this; one way is to use the recode function in
the car package:
new <- recode(var, " c('B', 'C') = 'D' ")
I hope that this helps,
John
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Frank E Harrell Jr Prof. of Biostatistics & Statistics Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._