Hi,
Most regression functions in R do that automatically for you. Here is an example
levels(iris$Species)
#> [1] "setosa" "versicolor" "virginica"
glm("Petal.Width ~ .", data = iris)
#>
#> Call: glm(formula = "Petal.Width ~ .", data = iris)
#>
#> Coefficients:
#> (Intercept) Sepal.Length Sepal.Width Petal.Length
#> -0.47314 -0.09293 0.24220 0.24220
#> Speciesversicolor Speciesvirginica
#> 0.64811 1.04637
#>
#> Degrees of Freedom: 149 Total (i.e. Null); 144 Residual
#> Null Deviance: 86.57
#> Residual Deviance: 3.998 AIC: -104.1
Created on 2021-12-09 by the reprex package (v2.0.1)
You can see that for the Species column 2 variables were created (there are 3 possible values).
Hope this helps,
PJ