title: In R, sort a list of dataframes by name, then calculate sum of two columns in each data frame
body: <p>I searched the forum for a bit, but I couldn't find a question that's similar to the one I have. Basically, I have a <code>list</code> of <code>dataframes</code> that have the same column names. I want to first sort the <code>dataframes</code> in the list by number, then calculate the <code>sum</code> of <code>Col1</code> and <code>Col2</code> in each <code>dataframes</code> and then store it in a vector that reflects the sorted list of <code>dataframes</code>.</p>
  
  <p>I thought list <code>[order(names(list))]</code> would work, but it didn't.</p>
  
  <p>For example:</p>
  
  <pre><code>df1 &lt;- data.frame(Col1=c(1,2,3,4,5),Col2=c(2,3,4,5,6), Col3=rep(a,5)) 
  df3 &lt;- data.frame(Col1=c(5,4,3,2,1),Col2=c(6,5,4,3,2), Col3=rep(a,5))
  df2 &lt;- data.frame(Col1=c(1,2,3,4,5),Col2=c(1,2,3,4,5), Col3=rep(a,5))
  list &lt;- list(df1, df3, df2)
  &gt;list
  $df1
  Col1 Col2 Col3
     1    2    a
     2    3    a
     3    4    a
     4    5    a
     5    6    a
  
  $df3
  Col1 Col2 Col3
     5    6    a
     4    5    a
     3    4    a
     2    3    a
     1    2    a
  
  $df2
  Col1 Col2 Col3
     1    1    a
     2    2    a
     3    3    a
     4    4    a
     5    5    a
  </code></pre>
  
  <p>First, I want to sort it, like this</p>
  
  <pre><code>$df1
  Col1 Col2 Col3
     1    2    a
     2    3    a
     3    4    a
     4    5    a
     5    6    a
  
  $df2
  Col1 Col2 Col3
     1    1    a
     2    2    a
     3    3    a
     4    4    a
     5    5    a
  
  $df3
  Col1 Col2 Col3
     5    6    a
     4    5    a
     3    4    a
     2    3    a
     1    2    a
  </code></pre>
  
  <p>Then, I want to get the sum of Col1 and Col2 in each dataframe, and store it in a new vector (let's call it <code>x</code>). The result should look like this</p>
  
  <pre><code>x
  35, 30, 35
  </code></pre>
  
  <p>With what I presented, I would imagine that there is both a <code>for-loop</code> solution and a <code>lapply</code> solution.</p>