I have an R script that creates a data frame with 61 columns. The data.frame is made by reading a bunch of csv files into a list of data.frames, then merging the list such that commonly named columns in each data.frame in the list populate the same column in the resulting data.frame.
Some of the columns that should be combined have been inconsistently named in the csv files (eg date.received vs received.on.date vs date.sample.received), and I was wondering what the best approach to combining them would be.
I had a couple ideas:
- rename the columns before merging in a big lapply over the list.
- combine the columns that should be the same once I have my data.frame, such that the column which has a value in that row is used
is the second approach possible (and how?) or is there a better way?