When you want to change the coding of a factor variable in R, you can use the levels() function. Recoding z as 1 = A, 2-6 = B, 7 = C d <- data.frame(z = gl(7, 1, 14)) d$zc <- factor(d$z) levels(d\$zc) <- list(A = 1, B = 2:6, C = 7) d Result…