Hi:

See ? levels. Here's a toy example:

> x <- factor(sample(0:2, 10, replace = TRUE))
> x
 [1] 1 2 1 0 2 2 2 2 2 1
Levels: 0 1 2

> levels(x) <- c(0, 1, 1)    # Change level 2 to 1
> x
 [1] 1 1 1 0 1 1 1 1 1 1
Levels: 0 1

HTH,
Dennis


On Fri, Jul 16, 2010 at 10:18 AM, CC <turtysmail@gmail.com> wrote:

> I am sure this is a very basic question:
>
> I have 600,000 categorical variables in a data.frame - each of which is
> classified as "0", "1", or "2"
>
> What I would like to do is collapse "1" and "2" and leave "0" by itself,
> such that after re-categorizing "0" = "0"; "1" = "1" and "2" = "1" --- in
> the end I only want "0" and "1" as categories for each of the variables.
>
> Also, if possible I would rather not create 600,000 new variables, if I can
> replace the existing variables with the new values that would be great!
>
> What would be the best way to do this?
>
> Thank you!
>
>
> --
> Thanks,
> CC
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]

