title: Expanding a Frequency Table Where the Variable Names are the Values
body: <p>I am working with a dataframe where each observation is linked to a specific ID, and I have a set of variables that define the "values" as if I had a factor variable. However, the value in the "cell" is the frequency. Here is a simplified version: </p>
  
  <pre><code>ID  1  2  3
  A   2  3  2
  B   1  4  1
  </code></pre>
  
  <p>I would like to get two vectors that expand the frequencies so that I can calculate an interpolated median for each ID. That is, I'd like something of the form: </p>
  
  <pre><code>A  B
  1  1
  1  2
  2  2
  2  2
  2  2
  3  3
  3
  </code></pre>
  
  <p>The <code>psych</code> package has a function <code>interp.median</code> that could then take each vector and return the interpolated median for each ID that I would like to include as a new variable in the original dataframe. I checked out the <code>vcdExtra</code> package which could maybe do this with its <code>expand.dft</code> function, but I'm not sure exactly how it would work. </p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>EDIT: To refine a bit more, <code>interp.median</code> would work best if the final result was a data frame, with NAs padded at the end. That is, something of the form: </p>
  
  <pre><code>A  B
  1  1
  1  2
  2  2
  2  2
  2  2
  3  3
  3  NA
  </code></pre>