[R] Recoding factors

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Oct 18 13:57:03 CEST 2004


On Mon, 18 Oct 2004, Uwe Ligges wrote:

> Neil Leonard wrote:
> 
> > I'm having a bit of trouble recoding factors in a fields.
> > 
> > I have a field which has the factors Singleton, Twin and Triplet.
> > I want to recode the field to have only the factors Singleton and Multiple.
>  >
> > Any advice?
> 
> Depends on what you are going to do with the Twin ...

?levels should help, though.

> x <- factor(c("Singleton", "Twin", "Triplet"))
> levels(x) <- c("Singleton", "Multiple", "Multiple")
> x
[1] Singleton Multiple  Multiple
Levels: Singleton Multiple

might be what is intended.

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list