title: count number of rows within 10 minutes of each other in R
body: <p>I have a table of transaction with their date-time. I'd like to count number of clusters of visits within 10 minutes of each other.</p>
  
  <pre><code>input=
  ID  visitTime
  1   11/10/2017 15:01
  1   11/10/2017 15:02
  1   11/10/2017 15:19
  1   11/10/2017 15:21
  1   11/10/2017 15:25
  1   11/11/2017 15:32
  1   11/11/2017 15:39
  1   11/11/2017 15:41
  </code></pre>
  
  <p>Here, there is a cluster starting on <code>11/10/2017 15:01</code> with 2 adjacent visits, one on <code>11/10/2017 15:19</code> with 3 visits (2 clusters on the date of <code>11/10/2017</code>). There is another cluster on <code>11/11/2017 15:32</code> with 3 calls. Giving the table below.</p>
  
  <pre><code>output =
  ID    Date    Cluster_count    Clusters_with_3ormore_visits
  1     11/10/2017    2          1
  1     11/11/2017    1          1
  </code></pre>
  
  <p>What I did:</p>
  
  <pre><code>input %&gt;% group_by(ID) %&gt;% arrange(visitTime) %&gt;%
  mutate(nextvisit = lead(visitTime),
       gapTime = as.numeric(interval(visitTime,nextvisit), 'minutes'),
       repeated = ifelse(gapTime&lt;= 10,1,0))
  </code></pre>
  
  <p>This can show the start and end of a sequence of visits, but doesn't give me a key to separate them and group them by.</p>
  
  <p>Appreciate any hints/ideas.</p>