title: R- How to read from multiple directories and apply function on same file names contained within different directories
body: <p>I have two directories that contain (share) files with the same name, e. g."file1","file2" and "file3", which can be found in dir1 as well as dir2.
  Now, I would like to read "file1" from dir1 and "file1" from dir2 in the first iteration and do some processing on both. In the second iteration, "dir1/file2" and "dir2/file2", and so forth.</p>
  
  <p>I used the following code to read all files from ONE directory:</p>
  
  <pre><code>setwd("dir1")
  file_list &lt;- list.files()
  
  process.Files &lt;- function(file) {
  myFile &lt;- read.table(file, header=TRUE, sep="")
  #process(myFile)
  return(someDataFrame)
  }
  
  dataset &lt;- do.call("cbind",lapply(file_list,
  FUN=function(files){  process.Files(files)  }))
  </code></pre>
  
  <p>Now, I need something like:</p>
  
  <pre><code>file_list1 &lt;- list.files("dir1/")
  file_list2 &lt;- list.files("dir2/")
  
  compare.Files &lt;- function(fileX,fileY) {
  myFileX &lt;- read.table(fileX, header=TRUE, sep="")
  myFileY &lt;- read.table(fileY, header=TRUE, sep="")
  #compare(myFileX,myFileY)
  return(someDataFrameWithComparisonResults)
  }
  
  #  I need to change this somehow to call compare.Files(files1,files2)
  dataset &lt;- do.call("cbind",lapply(file_list,
  FUN=function(files){  process.Files(files)  }))
  </code></pre>
  
  <p>How could I make it work?
  Thanks in advance.</p>