codes(x) codes(x) <- y
codes can be used to retrieve the underlying integer codes used for the levels of a factor and also to reset (a subset of) these codes. Examples x <- gl(3,5,15) codes(x)[3] <- 2