Assume we have a dataframe
x y 1 1 2 4 4 5
how can you add a new variable to the dataframe such that if x is less than or equal
If you have a very limited number of levels, you could try converting y into factor and change its levels.
y
> xy <- data.frame(x = c(1, 2, 4), y = c(1, 4, 5)) > xy$w <- as.factor(xy$y) > levels(xy$w) <- c("good", "fair", "bad") > xy x y w 1 1 1 good 2 2 4 fair 3 4 5 bad