Re: [R] Collapsing levels of a factor

2006-03-19 Thread Gregor Gorjanc
>> x <- factor(1:3, labels = c("b" , "f", "minus")) >> x > [1] b f minus > Levels: b f minus > > I want to change all "minus" to "b". I know that the simplest way to do this > is > >> levels(x) <- c("b", "f", "b") > > and also that > >> x[x == "minus"] <- "b" >> x <- factor(x) > > w

Re: [R] Collapsing levels of a factor

2006-03-17 Thread Gabor Grothendieck
Sorry, here is the code: > x <- ts(1:12) > y <- ifelse(rep(TRUE, 12), x, x) > str(x) Time-Series [1:12] from 1 to 12: 1 2 3 4 5 6 7 8 9 10 ... > str(y) int [1:12] 1 2 3 4 5 6 7 8 9 10 ... On 3/17/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > The problem is that ifelse strips attributes.

Re: [R] Collapsing levels of a factor

2006-03-17 Thread Gabor Grothendieck
The problem is that ifelse strips attributes. For example, consider this which has nothing to do with factors but illustrates the point with ifelse: > x <- ts(1:12) > y <- ifelse(TRUE, x, x) > str(x) Time-Series [1:12] from 1 to 12: 1 2 3 4 5 6 7 8 9 10 ... > str(y) int 1 On 3/17/06, Göran Br

[R] Collapsing levels of a factor

2006-03-17 Thread Göran Broström
> x <- factor(1:3, labels = c("b" , "f", "minus")) > x [1] b f minus Levels: b f minus I want to change all "minus" to "b". I know that the simplest way to do this is > levels(x) <- c("b", "f", "b") and also that > x[x == "minus"] <- "b" > x <- factor(x) works. But why not > x <- if