title: Add rows in a data.frame so that each group is of equal length
body: <p>I have the following data.frame, mimicking a time series analysis:</p>
  <pre><code>df &lt;- data.frame(country = rep(c(&quot;US&quot;, &quot;GB&quot;, &quot;DK&quot;), each = 18),
               y = runif(54),
               time = c(-8:9, 0:17, -17:0))
  </code></pre>
  <p>Meaning, I have 18 years of data, with an event of interest occurring somewhere within those 18 years. The <code>time</code> column sets that particular year to zero and counts forward / backward as appropriate.</p>
  <p>I need to make every group (US, GB, DK) the same size, set to the maximum that it could be, filling in all the missing data with <code>NA</code>. In other words, I'd need the final data.frame to look like this:</p>
  <pre><code>df2 &lt;- data.frame(country = rep(c(&quot;US&quot;, &quot;GB&quot;, &quot;DK&quot;), each = 18+17),
               y = c(rep(NA, 9), df[df$country == &quot;US&quot;,]$y, rep(NA, 8),
                     df[df$country == &quot;GB&quot;,]$y, rep(NA, 17),
                     rep(NA, 17), df[df$country == &quot;DK&quot;,]$y),
               time = rep(-17:17, times = 3))
  </code></pre>
  <p>In the real data, there are 176 countries, each with the intervention occurring in different years. So I really don't want to have to hard-code it like I just did! Is there a way to do this, perhaps with <code>dplyr</code>?</p>