title: Replacing values in a list based on the number of consecutive values they area a part of
body: <p>I have the following list:</p>
  
  <pre><code>my_list &lt;- list(c(1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1), c(0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0), c(0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1))
  &gt; my_list
  [[1]]
   [1] 1 1 1 0 1 1 1 1 1 1 0 1 1
  
  [[2]]
   [1] 0 0 0 0 1 1 0 1 1 1 1 1 0
  
  [[3]]
   [1] 0 1 1 1 1 1 1 1 1 0 0 0 1
  </code></pre>
  
  <p>Wherever there are fewer than four consecutive <code>1</code>s, I would like to replace those <code>1</code>s with <code>0</code>s. The resulting list should look like this:</p>
  
  <pre><code>&gt; my_new_list
  [[1]]
   [1] 0 0 0 0 1 1 1 1 1 1 0 0 0
  
  [[2]]
   [1] 0 0 0 0 0 0 0 1 1 1 1 1 0
  
  [[3]]
   [1] 0 1 1 1 1 1 1 1 1 0 0 0 0
  </code></pre>
  
  <p>I believe I have to use the <code>rle</code> and <code>inverse.rle</code> functions, but I can't figure out how to do it. Thanks for your help.</p>