# How to encode factor predictors in prediction models

The response variable as well as all predictor variables in my dataset are factors. I want to build a model for predicting the response variable. As I understand I have to first encode my predictor variables. I need advise on how to do the same in R.

I tried building knn & Random Forest models, but this is not working as the execution is never getting completed.

"rs" is the response variable and all others are predictor variables. "bt" depends on "td", but others are completely independent.

Below are the structure & head of my dataframe.

> str(df)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   17520 obs. of  10 variables:
$$rs : Factor w/ 8 levels "0","1","2","3",..: 1 5 1 3 3 3 2 1 5 8 ...$$ bno : Factor w/ 135 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
$$bttm: Factor w/ 13 levels "tm 1","tm 10",..: 5 12 10 7 10 12 1 13 7 6 ...$$ bwtm: Factor w/ 13 levels "tm 1","tm 10",..: 11 11 7 9 9 8 12 11 4 9 ...
$$bts : Factor w/ 348 levels "pl 100","pl 101",..: 207 295 114 246 328 318 312 14 147 118 ...$$ tw  : Factor w/ 13 levels "tm 1","tm 10",..: 7 9 5 12 5 1 11 8 9 7 ...
$$td : Factor w/ 2 levels "b","f": 1 2 2 1 1 2 1 2 1 2 ...$$ bwl : Factor w/ 282 levels "pl 10","pl 106",..: 60 160 123 71 139 9 109 229 6 148 ...
$$bt : Factor w/ 2 levels "1","2": 1 2 1 2 1 2 1 2 1 2 ...$$ ven : Factor w/ 41 levels "v 1","v 10","v 11",..: 6 21 35 26 34 13 23 10 17 25 ...
>