I need to be able to create a data frame from a set of passed in parameters. I realize I can hand type this, but I'm simplifying for the purposes of the question.
Given two vectors:
names <- c('Name', 'Height', 'DateOfBirth')
types <- c('character', 'integer', 'POSIXct')
How can I create a data frame with those names and data types? This works, but it creates everything as characters:
myDataFrame <- as.data.frame(setNames(replicate(length(myNames),character(0)), myNames))
I tried this, but it doesn't work:
myDataFrame <- as.data.frame(setNames(types, names))
I've searched and don't see anything. The setNames
function came from searching.