1

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))

with

for (i in file_groups) {
    print(i) 
}

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.

Ethan James
  • 41
  • 10
  • Suggested duplicates [How to make a list of data frames](https://stackoverflow.com/q/17499013/903061) – Gregor Thomas Dec 05 '18 at 20:23
  • Have you tried this code so far? You did not group "the files by similar names", you just assumed they were read already grouped. You are also missing a file, 175 * 5 = 1050. Are you trying to merge or rbind? They are not the same thing. – dcarlson Dec 05 '18 at 20:24
  • I do not see how this is similar or even a duplicate to the link above. – Ethan James Dec 05 '18 at 21:46
  • Yes. This part of the code is working so far. I have the correct file names in the groups. The issue was there was 3 groups that only had 3 so it messed it up but I have now fixed that. I need each group to be rbinded, then add a new colum as a reservior name for each row, then r bind all those groups together into one file is the goal – Ethan James Dec 05 '18 at 21:52

1 Answers1

0

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)

PDM
  • 74
  • 8