title: How to produce a binary variable that takes value of 0 before the last non-zero value of another variable and 1 after it
body: <p>Given the variable</p>
  <pre><code>a &lt;- c(1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0) 
  </code></pre>
  <p>I would like to mark the last non-zero value to produce a variable that takes value of 0 before the benchmark and 1 after it. In this case</p>
  <pre><code>b &lt;- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1)
  </code></pre>
  <p>A simple command that allows to mark the last non-zero value of a a column is</p>
  <pre><code>tail(which(a!=0),1) 
  </code></pre>
  <p>But how to create the variable I need conditional on such benchmark? Any help would be much appreciated!</p>