[R] How to change the levels of a variable???

John Fox jfox at mcmaster.ca
Fri Sep 21 16:39:52 CEST 2001

At 08:27 AM 21/09/2001 -0300, Ronaldo Reis Jr. wrote:
>I have a simple question.
>I have a variable with 3 levels.
>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.
>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

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 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

More information about the R-help mailing list