changing values
On Thu, 28 Jun 2001, Antonio Olinto wrote:
Dear R list members, I have a factor vector with levels 1, 2, 3 and 4. I want to re-group it:
1 and 2 will be 1 and 3 and 4 will be 2, e.g.:
x <- c(1, 1, 1, 2, 3, 2, 3, 4, ... ) x <- factor(x) What I have to do create a new vector where 1 1 1 2 3 2 3 4 ... is
transformed in 1 1 1 1 2 1 2 2 ... ? (I have more than 200 lines in my dataframe)
levels(x) <- c(1,1,2,2) x
[1] 1 1 1 1 2 1 2 2 Levels: 1 2 is the simplest answer.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._