Given the following mock data:
set.seed(123) x <- data.frame(let = sample(letters[1:5], 100, replace = T), num = sample(1:10, 100, replac
Just do y$let <- factor(y$let). Running factor on an existing factor variable will reset the levels to only those that are present.
y$let <- factor(y$let)
factor