title: R xts: transform all 0 values in a time series with the last found value different than 0
body: <p>I am working on an xts object that contains some 0s in one of the columns and I need to replace them with the last value different than 0 found in the sequence.</p>
  
  <p>For example, I am simplifying here using a regular R vector:</p>
  
  <pre><code>v = c(1, 2, 3, 0, 0, 0)
  </code></pre>
  
  <p>I need to change all the 0s with the last value != 0 in the sequence, in this case 3. The resulting vector should be:</p>
  
  <pre><code>&gt; v
  [1] 1 2 3 3 3 3
  </code></pre>
  
  <p>How can I achieve this, possibly using transform() or another vector operation?</p>