Change class of variables in a data frame using another reference data frame

You could try it like this:

Make sure both tables are in the same order:

variable_info <- variable_info[match(variable_info$variable_name, names(df)),]

Create a list of function calls:

funs <- sapply(paste0("as.", variable_info$variable_class), match.fun)

Then map them to each column:

df[] <- Map(function(dd, f) f(as.character(dd)), df, funs)

With data.table you could do it almost the same way, except you replace the last line by:

library(data.table)
dt <- as.data.table(df) # or use setDT(df)
dt[, names(dt) := Map(function(dd, f) f(as.character(dd)), dt, funs)]