I would like to create one dataframe of several .csv files without losing any columns (i.e. for any of the .csv's that don't have a particular column, that space would be filled with NA
. I would like this process to align them by column name but the order of the columns across .csv's also does not always match.
I've created a list of .csv files from a folder which only has said files
files <- dir("C:/...")
I would like to read in these .csv files into one dataframe. What I've got so far...
table_all <- do.call(rbind.fill(ldply(files, read.csv,
stringsAsFactors= TRUE, header= T, sep= ",")))
I assume the solution involves do.call
and some combination of rbind
, bind_rows
or rbind.fill
. I've read a bit about rbindlist
being computationally lighter, but it only matches by position, and as my .csv's have columns out of order, I need something to match by name.