I have a bunch of data frames with different variables. I want to read them into R and add columns to those that are short of a few variables so that they all have a common
We could create a helper function to create the column
fncols <- function(data, cname) { add <-cname[!cname%in%names(data)] if(length(add)!=0) data[add] <- NA data } fncols(mtcars, "mpg") fncols(mtcars, c("topspeed","nhj","mpg"))