Skip to content
Prev 105705 / 398503 Next

change factor level 1,2,3 to red,blue,dark

Aimin Yan <aiminy <at> iastate.edu> writes:
levels() help page has entry about this. Try

x <- factor(round(runif(n=10, min=1, max=3)))
x
 [1] 3 1 1 3 1 2 2 2 1 2
Levels: 1 2 3

levels(x) <- list(red=c(1), blue=c(2), dark=c(3))
x
 [1] dark red  red  dark red  blue blue blue red  blue
Levels: red blue dark

You have factor in data.frame, so you have to use

levels(myDF$x) <- ...


Gregor