Home > Back-end >  How can I read in a list of- and combine- multiple CSVs with duplicate ID columns?
How can I read in a list of- and combine- multiple CSVs with duplicate ID columns?

Time:03-23

I have a list of CSVs that contain data for individual animals. I have 2 CSVs for each animal so the ID column in each of those CSVs is the same. Also, one CSV for each individual contains many more columns than the other. How can I read in the list of CSVs and combine all CSVs into a single data frame?

RSF_df <- list.files("C:\\Users\\kujld016\\Desktop\\All\\Projects\\Thermal_Deer\\Analysis\\Output\\used_unusedPoints", 
                         pattern="*.csv", full.names=T) %>% 
          lapply(read_csv) %>%                                  
          bind_rows()

Error in check4duplicates(idcolumn, name) : 
  Not all ids in C:\Users\kujld016\Desktop\All\Projects\Thermal_Deer\Analysis\Output\used_unusedPoints/ UsedPoints_ A628 .csv are unique: "B82143"

CodePudding user response:

We can do,

RSF_df = list.files(getwd(), pattern=".csv", full.names=T) %>%  lapply(., read.csv) 

library(plyr)

RSF_df = ldply(RSF_df, data.frame)

CodePudding user response:

library(data.table)
rbindlist(lapply(files.to.read, fread), use.names = TRUE, fill = TRUE)
  • Related