R: Loop for importing multiple xls as df, rename column of one df and then merge all df's <p>The below is driving me a little crazy and I’m sure theres an easy solution.</p> <p>I currently use R to perform some calculations from a bunch of excel files, where the files are monthly observations of financial data. The files all have the exact same column headers. Each file gets imported, gets some calcs done on it and the output is saved to a list. The next file is imported and the process is repeated. I use the following code for this:</p> <pre><code>filelist &lt;- list.files(pattern = "\\.xls") universe_list &lt;- list() count &lt;- 1 for (file in filelist) { df &lt;- read.xlsx(file, 1, startRow=2, header=TRUE) *perform calcs* universe_list[[count]] &lt;- df count &lt;- count + 1 } </code></pre> <p>I now have a problem where some of the new operations I want to perform would involve data from two or more excel files. So for example, I would need to import the Jan-16 and the Jan-15 excel files, perform whatever needs to be done, and then move on to the next set of files (Feb-16 and Feb-15). The files will always be of fixed length apart (like one year etc) </p> <p>I cant seem to figure out the code on how to do this… from a process perspective, Im thinking 1) need to design a loop to import both sets of files at the same time, 2) create two dataframes from the imported data, 3) rename the columns of one of the dataframes (so the columns can be distinguished), 4) merge both dataframes together, and 4) perform the calcs. I cant work out the code for steps 1-4 for this!</p> <p>Many thanks for helping out</p>