title: How do I count the number of rows that contain a value earlier than another row in R?
body: <p>I've imported data from a CSV into RStudio using read.table
  The data is of the type &quot;list&quot; and looks like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Client</th>
  <th>Goal1</th>
  <th>Goal2</th>
  <th>Time</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>123</td>
  <td>0</td>
  <td>1</td>
  <td>9:00</td>
  </tr>
  <tr>
  <td>123</td>
  <td>1</td>
  <td>0</td>
  <td>9:15</td>
  </tr>
  <tr>
  <td>234</td>
  <td>1</td>
  <td>0</td>
  <td>9:12</td>
  </tr>
  <tr>
  <td>234</td>
  <td>0</td>
  <td>1</td>
  <td>9:30</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I need to calculate the number of Clients that reached both Goal1 and Goal2, but Goal2 has to be reached after the Client reached Goal1.
  So, in this example, Client 123 reached Goal2 before Goal1 and doesn't count. Client 234 reached Goal2 after Goal1 and does count.</p>
  <p>I made a summary like this</p>
  <pre><code>scores %&gt;% 
    summarise(count_all = n_distinct(Client), 
              count_goal_1 = uniqueN(Client[Goal1 &gt; 0]), 
              count_goal_2 = uniqueN(Client[Goal2 &gt; 0]), 
              count_overlap = uniqueN(ClientID[Goal1 &gt; 0 &amp; Goal2 &gt; 0]),
              percentage_overlap = (count_overlap / count_goal_1)*100
    )
  </code></pre>
  <p>but I don't know how to make this conditional.</p>