Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
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)
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.