R Program to Convert Factors to Characters

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.

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges