R; Rbind Excel files from a List of vectors of files in R

I have web-scraped ~1000 Excel Files into a specific folder on my computer I then read these files in which returned a value of chr [1:1049] I then grouped these files by similar names which was every 6 belonged in one group This returned a List of 175, with values of the group of 6 file names.

I am confused on how I would run a loop that would merge/rbind the 6 file names for each group from that list. I would also need to remove the first row but I know how to do that part with read.xlsx

My code so far is

setwd("C:\\Users\\ewarren\\OneDrive\\Documents\\Reservoir Storage")
files <- list.files()
file_groups <- split(files, ceiling(seq_along(files)/6))


for (i in file_groups) {

returning each group of file names

The files for example are: files

They are each compromised of two columns, date and amount I need to add a third to each that is the reservoir name That way when all the rows from all the files are combined theres a date, an amount, and a reservoir. If I do them all at once w/o the reservoir, I wouldnt know which rows belong to which.

1 answer

  • answered 2018-12-05 20:19 PDM

    You can use startRow = 2 to not get the first row in read.xlsx

    for merging the groups of file. If you have an identifier e.g. x in each file that matches with their others in the group, but not with the ones which are in other groups.

    you have make a list group1 <- list.files(pattern = "x) then use do.call(cbind, group1)