x <- c("a", "b", "c")
class(x)
#> [1] "character"
x <- as.factor(x)
class(x)
#> [1] "factor"
x
#> [1] a b c
#> Levels: a b c
levels(x)
#> [1] "a" "b" "c"
If you need more specific help, please make your questions with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.
If you've never heard of a reprex before, you might want to start by reading this FAQ: