f <- fct(letters[rpois(100, 10)])
unique(f) # in order of appearance
fct_unique(f) # in order of levels
f <- fct(letters[rpois(100, 2)], letters[1:20])
unique(f) # levels that appear in data
fct_unique(f) # all possible levels
Run the code above in your browser using DataLab