I have a dataframe where all columns have a class character, but many of the columns must have a numeric or integer class. I also have a character vector containing the desired class for each column, for example.
classes <- c("integer", "integer", "numeric", "character", "logical", "numeric", ... )
I am looking for a way to quickly set the class of each column using this classesvector without a loop.
I was hoping this would be a way to make it look like a naming con, for example.
names(df) <- names
where namesis the vector character, or in my case
class(df) <- classes
source
share