Example: Convert Factors to Characters in R
factor1 <- factor(c("Male", "Female", "Transgender"))
# convert factor to character
result <- as.character(factor1)
print(result)
Output
[1] "Male" "Female" "Transgender"
In the above example, we have used the as.character()
function to convert the factor named factor1 to character.
As we can see, each element of factor1 is displayed separately as a character.