# [R] changing values

Antonio Olinto aolinto at bignet.com.br
Thu Jun 28 17:09:24 CEST 2001

```Thanks very much Dr. Ripley.

After thinking a little more on my question I decide to use "ifelse"

x <- c(x)
x1 <- ifelse (x <=2, 1, x)
x2 <- ifelse (x1>=3, 2, x1)
x <- factor(x2)

it works, but "levels(x) <- c(1,1,2,2)" is too much easier.

Thanks a lot.

Antônio Olinto

----- Original Message -----
From: "Prof Brian Ripley" <ripley at stats.ox.ac.uk>
To: "Antonio Olinto" <aolinto at bignet.com.br>
Cc: <r-help at stat.math.ethz.ch>
Sent: Thursday, June 28, 2001 11:34 AM
Subject: Re: [R] 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
>
>
> --
> 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```