[R] Making an aggregated factor variable from an existing one

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Thu Jan 17 14:30:42 CET 2013


Hi, Antti,

you should look at

?levels

(and particular its "Examples" section) to find out how to use

levels( X) <- c( "new1", ......., "newk")

to achieve what you want.

  Regards  --  Gerrit


On Thu, 17 Jan 2013, Antti Simola wrote:

> Hi,
>
> This is quite simple data manipulation task and I need help for it. I want to 
> make new factor variable that is an aggregation of an existing factor.
>
> This works as I intended:
>
> X[Y == "original label"] <- " new label"
>
> How to make following work then (to make coding more convenient):
>
> original.labels <- c("ol.1","ol.2","ol.3")
>
> X[Y == original.labels] <- "new label"
>
> Cheers,
>
> Antti
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list