To convert a variable in a dataframe from character to factor, you can use the factor()
function in R.
main.r453 chars16 lines
In the above example, we first created a dataframe with three variables: name, gender and age, with gender as a character variable. We then used the factor()
function to convert the gender variable to a factor variable. We checked the structure of the dataframe before and after the conversion to verify that the conversion was successful.
gistlibby LogSnag