title: In R need count of consecutive years played
body: <p>I need to know for each player who played for the New York Mets (NYM) how many consecutive years they played, starting with the year they first joined the team.</p>
  <p><strong>Sample Input</strong></p>
  <p><a href="https://i.stack.imgur.com/VApnL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VApnL.png" alt="Sample Input" /></a></p>
  <p>In the sample output below, there is an error I need fixed. Player C started playing for the Mets in 1984 (see Sample Input above), but his first stint with the team ended in 1987 as he did not play for them in 1988, so though the Sample Output shows it as 5 consecutive years, it should be 4.</p>
  <p>I would prefer a dplyr solution but am open to others.</p>
  <p>I checked the available stackoverflow solutions, but could not find one that directly addressed my situation. If one exists, I would appreciate it if you could share its link.</p>
  <p><strong>Sample Output</strong></p>
  <p><a href="https://i.stack.imgur.com/geKyq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/geKyq.png" alt="Sample Output" /></a></p>
  <p><strong>Here is my code so far:</strong></p>
  <pre><code>cym |&gt;
    filter(Team == &quot;NYM&quot;) |&gt;
    group_by(Player) |&gt;
    count(name = &quot;Consec_Yrs&quot;)
  </code></pre>
  <p><strong>Dput(cym):</strong></p>
  <pre><code>structure(list(Player = c(&quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, 
  &quot;B&quot;, &quot;C&quot;, &quot;C&quot;, &quot;C&quot;, &quot;C&quot;, &quot;C&quot;, &quot;C&quot;, &quot;C&quot;, &quot;C&quot;, &quot;D&quot;), Team = c(&quot;NYM&quot;, 
  &quot;NYM&quot;, &quot;LAD&quot;, &quot;LAD&quot;, &quot;SFG&quot;, &quot;NYM&quot;, &quot;NYM&quot;, &quot;NYM&quot;, &quot;PHA&quot;, &quot;NYM&quot;, 
  &quot;NYM&quot;, &quot;NYM&quot;, &quot;NYM&quot;, &quot;ATL&quot;, &quot;ATL&quot;, &quot;NYM&quot;, &quot;NYM&quot;), Year = c(1970, 
  1971, 1972, 1973, 1980, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 
  1987, 1987, 1988, 1989, 2000)), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;
  ), row.names = c(NA, -17L))
  </code></pre>