title: Find the ratio between each column entry and the following entry, for every column, for a list of data.frames in R
body: <p>I have a dataset that looks like this, where there are ~500 dataframes in a list:</p>
  <pre><code>1   1   1   1   1   1   1   1   1
  1   1   1   1   1   1   1   1   2
  1   1   1   1   1   1   1   1   1
  1   1   1   1   1   1   1   1   2
  1   1   1   1   1   1   1   1   1
  1   1   1   1   1   1   1   1   2
  1   1   1   1   1   1   1   1   1
  1   1   1   1   1   1   1   1   2
  1   1   1   1   1   1   1   1   1
  1   1   1   1   1   1   1   1   2
  1   1   1   1   1   1   1   1   1
  1   1   1   1   1   1   1   1   2
  1   1   1   1   1   1   1   1   1
  1   1   1   1   1   1   1   1   2
  1   1   1   1   1   1   1   1   1
  1   1   1   1   1   1   1   1   2
  1   1   1   1   1   1   1   1   1
  1   1   1   1   1   1   1   1   2
  1   1   1   1   1   1   1   1   1
  1   1   1   1   1   1   1   1   2
  </code></pre>
  <p>Within each column, I want to find the ratio of the first value to the second value, then the third value to the fourth, then the fifth value to the six, etc. Then I want to do that to every column, and output it to a new data frame. Like this:</p>
  <pre><code>
  1   1   1   1   1   1   1   1   0.5                         
  1   1   1   1   1   1   1   1   0.5
  1   1   1   1   1   1   1   1   0.5
  1   1   1   1   1   1   1   1   0.5
  1   1   1   1   1   1   1   1   0.5
  1   1   1   1   1   1   1   1   0.5 
  1   1   1   1   1   1   1   1   0.5
  1   1   1   1   1   1   1   1   0.5
  1   1   1   1   1   1   1   1   0.5                         
  1   1   1   1   1   1   1   1   0.5
  
  </code></pre>
  <p>And I want to be able to apply it to the list of data frames at one time.</p>
  <p>The closest I've gotten is with one data frame, and only one column... where I would also have to delete every other value (which is ok, I can do that in post processing).</p>
  <pre><code>ratio = df[[1]][,1]/lag(df[[1]][,1],1)
  
  </code></pre>
  <p>But again, it needs to do every column into the new data frame, applied to a list of data frames.</p>
  <p>Note that the actual values can be anything from 0 to 2000, they are not necessarily all 1's and 2's.</p>
  <p><strong>data</strong></p>
  <pre><code>df &lt;- data.frame(cbind(1, 1, 1, 1, 1, 1, 1, 1, rep(1:2, 10)))
  ll &lt;- list(df, df, df)
  </code></pre>