title: Apply "one-column function" to whole data frame
body: <p>Here is a sample data frame <code>df</code> and a vector <code>s</code>:</p>
  
  <pre><code>x1 &lt;- c(12:4, 5:8, NA, NA)
  x2 &lt;- c(15:8, 9:15)
  df &lt;- data.frame(x1, x2)
  s &lt;- c(9,8)
  </code></pre>
  
  <p>Now I want to delete the values in each column before the row numbers given in <code>s</code> which works with </p>
  
  <p><code>df1 &lt;- df[s[1]:nrow(df[1]), 1]</code></p>
  
  <p>for a single column. But I can't get it to work for the whole data frame.
  I've tried the following (and various other functions):</p>
  
  <pre><code>rec  &lt;- function(x){df[s[x]:nrow(df[x]), x]}
  df1 &lt;- lapply(df, rec)
  </code></pre>
  
  <p>But I'm always getting errors like that:</p>
  
  <pre><code>Error in `[.data.frame`(df, s[x]:nrow(df[x]), x) : undefined columns selected
  </code></pre>
  
  <p>Don't know where the problem is. Any suggestions?</p>