title: Changing the dimensions of a data frame in R
body: <p>I have a data set with dozens of columns and thousands of rows. Here I present just a toy example:</p>
  
  <pre><code>trN &lt;- c(0,0,0,0,1,1,1,1)
  tt &lt;- c(1,2,3,4,1,2,3,4)
  varX &lt;- c(1,5,NA,9,2,NA,8,4)
  d &lt;- as.data.frame(cbind(trN, tt, varX))
  </code></pre>
  
  <p>The first thing that I do is to spline interpolate column <code>varX</code> as a function of column <code>tt</code> for each <code>trN</code>. An operation that is easily done with <code>ddply</code> from the <code>plyr</code> package.</p>
  
  <pre><code>ddply(d, .(trN), mutate, varXint = spline(tt, varX, xout = tt)$y)
  </code></pre>
  
  <p>But suppose that I would like to also change the dimension (number of rows) of the new data frame. For instance, I would like to have a set of values specifying where interpolation is to take place (<code>xout</code>) that has a different length then <code>tt</code>. Obviously, the approach here below doesn't work, because with <code>mutate</code> the new column needs to have the same length as the columns of the original data frame:</p>
  
  <pre><code>ddply(d, .(trN), mutate, varXint = spline(tt, varX, xout = seq(1, 4, by = 1.5))$y)
  </code></pre>
  
  <p>Does anyone have a suitable solution or any kind of suggestion? I would prefer to have a solution based on the <code>plyr</code> package, because I can take advantage of the implemented parallelization.</p>