how do I set multiple existing columns in a dataframe to factors?

You can do something like this

library(dplyr)

dataInExample  %>% 
    mutate(across(.cols = c(b, g),
                  .fns = as.factor))

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

1 Like