R Program to Convert Factors to Characters

In this example, we will learn to convert factors to characters in R using the as.character() function.

Example: Convert Factors to Characters in R

factor1 <- factor(c("Male", "Female", "Transgender"))
# convert factor to character 
result <- as.character(factor1)


[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.