title: Duplicate first occurence of string into column of data frame
body: <p>In a data frame, I am attempting to duplicate the first occurence of a string into the same column, but also into the neighbouring column. More specifically, I want the first occurence of a string in column v1 to be duplicated and inserted above itself and above the same row in column v2, as exemplified in the mock data frame below:</p>
  <p>Input:</p>
  <pre><code>df_1&lt;-data.frame(&quot;v1&quot;=c(rep(&quot;a&quot;,times=3),rep(&quot;aa&quot;,times=4)),&quot;v2&quot;=c(c(&quot;b&quot;,&quot;c&quot;,&quot;d&quot;),c(&quot;bb&quot;,&quot;cc&quot;,&quot;dd&quot;,&quot;ee&quot;)))
  df_1
        v1 v2
      1  a  b
      2  a  c
      3  a  d
      4 aa bb
      5 aa cc
      6 aa dd
      7 aa ee
  </code></pre>
  <p>Expected output:</p>
  <pre><code>df_2&lt;-data.frame(&quot;v1&quot;=c(rep(&quot;a&quot;,times=4),rep(&quot;aa&quot;,times=5)),&quot;v2&quot;=c(c(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;),c(&quot;aa&quot;,&quot;bb&quot;,&quot;cc&quot;,&quot;dd&quot;,&quot;ee&quot;)))
  df_2
      v1 v2
      1  a  a
      2  a  b
      3  a  c
      4  a  d
      5 aa aa
      6 aa bb
      7 aa cc
      8 aa dd
      9 aa ee
  </code></pre>
  <p>So in this case, the first occurence of &quot;a&quot; and &quot;aa&quot; has been duplicated and inserted into the same data frame above it's first occurence.</p>
  <p>I hope my question makes sense.</p>
  <p>Best,
  Rikki</p>