title: Merging more than 2 dataframes in R by rownames
body: <p>I gather data from 4 df's and would like to merge them by rownames. I am looking for an efficient way to do this. This is a simplified version of the data I have. </p>
  
  <pre><code>df1           &lt;- data.frame(N= sample(seq(9, 27, 0.5), 40, replace= T),
                              P= sample(seq(0.3, 4, 0.1), 40, replace= T),
                              C= sample(seq(400, 500, 1), 40, replace= T))
  df2           &lt;- data.frame(origin= sample(c("A", "B", "C", "D", "E"), 40,
                                             replace= T),
                              foo1= sample(c(T, F), 40, replace= T),
                              X= sample(seq(145600, 148300, 100), 40, replace= T),
                              Y= sample(seq(349800, 398600, 100), 40, replace= T))
  df3           &lt;- matrix(sample(seq(0, 1, 0.01), 40), 40, 100)
  df4           &lt;- matrix(sample(seq(0, 1, 0.01), 40), 40, 100)
  rownames(df1) &lt;- paste("P", sprintf("%02d", c(1:40)), sep= "")
  rownames(df2) &lt;- rownames(df1)
  rownames(df3) &lt;- rownames(df1)
  rownames(df4) &lt;- rownames(df1)
  </code></pre>
  
  <p>This is what I would normally do: </p>
  
  <pre><code># merge df1 and df2
  dat           &lt;- merge(df1, df2, by= "row.names", all.x= F, all.y= F) #merge
  rownames(dat) &lt;- dat$Row.names #reset rownames
  dat$Row.names &lt;- NULL  #remove added rownames col
  
  # merge dat and df3
  dat           &lt;- merge(dat, df3, by= "row.names", all.x= F, all.y= F) #merge
  rownames(dat) &lt;- dat$Row.names #reset rownames
  dat$Row.names &lt;- NULL  #remove added rownames col
  
  # merge dat and df4
  dat           &lt;- merge(dat, df4, by= "row.names", all.x= F, all.y= F) #merge
  rownames(dat) &lt;- dat$Row.names #reset rownames
  dat$Row.names &lt;- NULL #remove added rownames col
  </code></pre>
  
  <p>As you can see, this requires a lot of code. My question is if the same result can be achieved with more simple means. I've tried (without success): UPDATE: this works now!</p>
  
  <pre><code>MyMerge       &lt;- function(x, y){
    df            &lt;- merge(x, y, by= "row.names", all.x= F, all.y= F)
    rownames(df)  &lt;- df$Row.names
    df$Row.names  &lt;- NULL
    return(df)
  }
  dat           &lt;- Reduce(MyMerge, list(df1, df2, df3, df4))
  </code></pre>
  
  <p>Thanks in advance for any suggestions</p>