title: Replace X consecutive repeated zero-values with NA in data frame (R)
body: <p>I have a data frame with a daily value for several users. The users have different start dates, so I have assigned NA for the values before the first use and zero-values for any cells without values thereafter. I have used the following loop to do this:</p>
  <pre><code>for (i in seq_along(df)) {
   isna &lt;- is.na(df[[i]])
   nonna &lt;- match(FALSE,isna)
   id &lt;- which(isna)
   df[[i]][id[id&gt;nonna]] &lt;- 0
  }
  </code></pre>
  <p>However, some of the users have a lot of zero-values towards the end, indicating that they have stopped using the service. I would like to set also these values to NA, if there are more than 100 zero-values in the end of the data frame. I have not succeeded in doing this, and any suggestions would be appreciated.</p>