title: How to distribute or "rotate" cell values of a dataframe column so that they fill blank rows above?
body: <p>I'm having a hard putting this into the form of a question. I have situation where the data in a column (column B) were recorded in such a way that all the values with respect to an indicator (column A) ended up in the bottom-most row within each value of the indicator. Or more simply, like this:</p>
  <pre class="lang-r prettyprint-override"><code>(my_df &lt;- data.frame(
      A = c(rep(1, 6), rep(2, 6)),
      B = c(rep(NA, 5), &quot;a,b,c,d,e,f&quot;, rep(NA, 5), &quot;g,h,i,j,k,l&quot;)
  ))
  #&gt;    A           B
  #&gt; 1  1        &lt;NA&gt;
  #&gt; 2  1        &lt;NA&gt;
  #&gt; 3  1        &lt;NA&gt;
  #&gt; 4  1        &lt;NA&gt;
  #&gt; 5  1        &lt;NA&gt;
  #&gt; 6  1 a,b,c,d,e,f
  #&gt; 7  2        &lt;NA&gt;
  #&gt; 8  2        &lt;NA&gt;
  #&gt; 9  2        &lt;NA&gt;
  #&gt; 10 2        &lt;NA&gt;
  #&gt; 11 2        &lt;NA&gt;
  #&gt; 12 2 g,h,i,j,k,l
  </code></pre>
  <p><sup>Created on 2022-01-28 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v2.0.1)</sup></p>
  <p>I am trying to find a simple way to distribute the cell contents upward so that they are in their correct rows, with respect to their respective codes:</p>
  <pre class="lang-r prettyprint-override"><code>(expected_df_1 &lt;- data.frame(
      A = c(rep(1, 6), rep(2, 6)),
      B = c(letters[1:6], letters[7:12])
  ))
  #&gt;    A B
  #&gt; 1  1 a
  #&gt; 2  1 b
  #&gt; 3  1 c
  #&gt; 4  1 d
  #&gt; 5  1 e
  #&gt; 6  1 f
  #&gt; 7  2 g
  #&gt; 8  2 h
  #&gt; 9  2 i
  #&gt; 10 2 j
  #&gt; 11 2 k
  #&gt; 12 2 l
  </code></pre>
  <p><sup>Created on 2022-01-28 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v2.0.1)</sup></p>
  <p>This would also be fine:</p>
  <pre class="lang-r prettyprint-override"><code>(expected_df_2 &lt;- data.frame(
      A = c(rep(1, 6), rep(2, 6)),
      B = c(rep(NA, 5), &quot;a,b,c,d,e,f&quot;, rep(NA, 5), &quot;g,h,i,j,k,l&quot;),
      C = c(letters[1:6], letters[7:12])
  ))
  #&gt;    A           B C
  #&gt; 1  1        &lt;NA&gt; a
  #&gt; 2  1        &lt;NA&gt; b
  #&gt; 3  1        &lt;NA&gt; c
  #&gt; 4  1        &lt;NA&gt; d
  #&gt; 5  1        &lt;NA&gt; e
  #&gt; 6  1 a,b,c,d,e,f f
  #&gt; 7  2        &lt;NA&gt; g
  #&gt; 8  2        &lt;NA&gt; h
  #&gt; 9  2        &lt;NA&gt; i
  #&gt; 10 2        &lt;NA&gt; j
  #&gt; 11 2        &lt;NA&gt; k
  #&gt; 12 2 g,h,i,j,k,l l
  </code></pre>
  <p><sup>Created on 2022-01-28 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v2.0.1)</sup></p>
  <p>I can't for the life of me find a solution to this. Ideas? Preferably I'd like to stay within the <code>tidyverse</code> framework if possible, but I'll take any suggestions!</p>