I have a data.frame and I want to change levels of a factor variable so I do this:
> df1 <- data.frame(id = 1:5, fact1 = factor(letters[1:5])) > head(df
you need to return the full object x rather than just the result of your assignment (which is the string missing).
x
missing
changeLevel1 <- function(x){ levels(x)[which(levels(x) == 'a')] <- 'missing' return (x) }