There are a few ways to do this. If you want to change particular columns, you can use the mutate_at function from dplyr and indicate the columns by their numeric position or by name.
DF <- data.frame(A = 1:3, B = c("D", "F", "W"), C = c("U", "I", "U"),
D = c("Q", "W", "E"), E = 3:5, stringsAsFactors = FALSE)
str(DF)
#> 'data.frame': 3 obs. of 5 variables:
#> $ A: int 1 2 3
#> $ B: chr "D" "F" "W"
#> $ C: chr "U" "I" "U"
#> $ D: chr "Q" "W" "E"
#> $ E: int 3 4 5
library(dplyr)
MakeNum <- function(x) as.numeric(as.factor(x))
DF <- mutate_at(DF, 2:4, MakeNum)
str(DF)
#> 'data.frame': 3 obs. of 5 variables:
#> $ A: int 1 2 3
#> $ B: num 1 2 3
#> $ C: num 2 1 2
#> $ D: num 2 3 1
#> $ E: int 3 4 5
Created on 2020-02-27 by the reprex package (v0.3.0)
You can also use mutate_if() to affect all columns that meet a certain condition, such as all character columns