Hi Nikhil,
The problem is that your initial "as.factor(0)" causes x to have
values of "1" : "20" instead of 1 : 20. There are two possible
solutions:
1)
> library(car)
> x <- 1:20
> y <- as.factor(recode(x, " 1:5='A'; 6:10='B'; 11:15='C'; 16:20='D' "))
> y
[1] A A A A A B B B B B C C C C C D D D
I am having trouble with the recode function that is provided in the
CAR package. I trying to create a new factors based on existing factors.
E.g.
>x <- as.factor(1:20)
>y <- recode(x, " 1:5='A'; 6:10='B'; 11:15='C'; 16:20='D' ")
>y
[1] A A A A A 6 7 8 9 A A A A A A A A A A A
Levels: 6 7 8 9
2 matches
Mail list logo