I'm wanting to create a function that produces an empty dataframe, where the columns are passed as arguments in the function. My current attempt looks like this:
create_df<-function(column1, column2){
df <- data.frame(column1=character(),
column2=numeric(),
stringsAsFactors = FALSE)
}
df <- create_df(a,b)
While this code succeeds in creating an empty data.frame
, the column names are column1
and column2
rather than a
and b
. Is there a straightforward way to fix this?