title: Is there a way to use the lead function to figure out the first row that meets a condition?
body: <p>Hi I have a dataframe as such,</p>
  <pre><code>df= structure(list(a = c(1, 3, 4, 6, 3, 2, 5, 1), b = c(1, 3, 4, 
                                                      2, 6, 7, 2, 6), c = c(6, 3, 6, 5, 3, 6, 5, 3), d = c(6, 2, 4, 
                                                                                                           5, 3, 7, 2, 6), e = c(1, 2, 4, 5, 6, 7, 6, 3), f = c(2, 3, 4, 
                                                                                                                                                                2, 2, 7, 5, 2)), .Names = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;), row.names = c(NA, 
                                                                                                                                                                                                                                         8L), class = &quot;data.frame&quot;)
  df$total = apply ( df, 1,sum )
  df$row = seq ( 1, nrow ( df ))
  </code></pre>
  <p>so the dataframe looks like this.</p>
  <pre><code>    &gt; df
    a b c d e f total row
  1 1 1 6 6 1 2    17   1
  2 3 3 3 2 2 3    16   2
  3 4 4 6 4 4 4    26   3
  4 6 2 5 5 5 2    25   4
  5 3 6 3 3 6 2    23   5
  6 2 7 6 7 7 7    36   6
  7 5 2 5 2 6 5    25   7
  8 1 6 3 6 3 2    21   8
  </code></pre>
  <p>what I want to do is figure the first leading row where the total is greater than the current. For example for row 1 the total is 17 and the nearest leading row &gt;= 17 would be row 3.</p>
  <p>I could loop through each row but it gets really messy. Is this possible?
  thanks in advance.</p>