How to obtain a position of last non-zero element : <p>I've got a binary variable representing if event happened or not:</p>

<pre><code>event &lt;- c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0)
</code></pre>

<p>I need to obtain a variable that would indicate the time when the last event happened. The expected output would be:</p>

<pre><code>last_event &lt;- c(0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 13, 13, 13, 13)
</code></pre>

<p>How can I obtain that with base R, tidyverse or any other way?</p>
