title: Using dplyr to filter rows
body: <p>I have a dataframe</p>
  
  <pre><code>soDf &lt;- structure(list(State = c("Exception", "Exception", "Exception",  "Exception", "Approval", "Processing"), User = c("1","2", "1", "3", "1", "4"), Voucher.Number = c(10304685L, 10304685L, 10304685L,10304685L, 10304685L, 10304685L),  Queue.Exit.Date = c("8/24/2016 14:59", "8/26/2016 13:25", "8/26/2016 15:56", "8/26/2016 16:13", "8/26/2016 16:25", "8/26/2016 17:34")),.Names = c("State", "User", "Voucher.Number","Queue.Exit.Date"), row.names = 114:119, class = "data.frame")
  </code></pre>
  
  <p>I have a list of rules that I want to filter rows by:</p>
  
  <p>One of the rules being </p>
  
  <pre><code>(Voucher.Number == lag(Voucher.Number)) &amp; (State == 'Exception' &amp; lag(State) == 'Exception' )
  </code></pre>
  
  <p>If the current and lag voucher number are equal, and both have an exception tag, then count mark that row as <code>True</code>.</p>
  
  <p>When I apply this rule with a couple other it returns the <strong>4th</strong> row as <code>True</code> when it should be returned as <code>False</code></p>
  
  <pre><code>       State User Voucher.Number Queue.Exit.Date toFilt
  1  Exception    1       10304685 8/24/2016 14:59     NA
  2  Exception    2       10304685 8/26/2016 13:25   TRUE
  3  Exception    1       10304685 8/26/2016 15:56   TRUE
  4  Exception    3       10304685 8/26/2016 16:13   TRUE
  5   Approval    1       10304685 8/26/2016 16:25  FALSE
  6 Processing    4       10304685 8/26/2016 17:34  FALSE
  </code></pre>
  
  <p>Here is the code I used with all of the filtering rules</p>
  
  <pre><code>soDf &lt;- soDf %&gt;%
    arrange(Voucher.Number, Queue.Exit.Date)%&gt;%
    mutate(toFilt =  ((User == lag(User)&amp; Voucher.Number ==lag(Voucher.Number)))|
             ((Voucher.Number != lag(Voucher.Number)) &amp; State == "Exception") |
             ((Voucher.Number == lag(Voucher.Number)) &amp; (State == 'Exception' &amp; lag(State) == 'Exception' ))|
             ((Voucher.Number == lag(Voucher.Number)) &amp; (User == lag(User))))  
  </code></pre>