I am getting familiar with recode
from dplyr
V0.5. Am I missing something? Seems like Recode
from car
is way more efficent. Unless I am doing something wrong:
This works:
x <- c("a", "b", "c")
y <- dplyr::recode(x, a = 1, b = 2, c= 3)
y
But not when you have a factor:
xf <- factor(c("a", "b", "c"))
yf<- dplyr::recode(xf, a = 1, b = 2, c= 3)
Error: `a` has type 'double' not 'character'
Seems like you have to treat it as character and use recode_factor so that it goes back to factor
Dyf <- dplyr::recode_factor(as.character(xf), a = 1, b = 2, c= 3)
Dyf
That would work but seems pretty verbose??? Recode
from car
would do it simply with:
Cyf <- Recode(x, " 'a'=1; 'b'= 2; 'c' = 3 ")
Cyf [1] 1 2 3
Levels: 1 2 3
I am missing something?
THANKS