What is an elegant way to change the data types of data frames columns from a list of data type names?
Here's an example (change_to_data_types function is what I'm looking for):
my_df <- iris
my_types <- c("factor", "character", "double", "logical", "character")
my_df <- my_df %>% change_to_data_types(my_types)
my_types has the same number of elements as the number of columns in my_df and the conversion is done in the same order.
This is an example of an 'inelegant' way
my_df$Sepal.Length <- my_df$Sepal.Length %>% as.factor()
my_df$Sepal.Width <- my_df$Sepal.Width %>% as.character()
#etc...