Most Machine learning algorithms require number as input. That is why we convert categorical values into factors to get numerical values. We also don't have to deal with dummy variables.
The functions factor() and as.factor() are used to convert variables into factors.