Question

I have an R data frame with some variables that are stored as numeric but are actually categorical. How do I convert one specific column's data type of an existing data frame from numeric to factor?

Was it helpful?

Solution

You can use:

dat$col <- as.factor(dat$col)

where dat is the name of your data frame and col the name of the column.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top