In R we have a special object called factor. In a simple way we can say that factor is a categorical variable, and it is very important to statistical modeling (more information about this object: help page in R ?factor, or you can find a good review here). It is a very efficient way to…