 <p>I'm feeling rather clever about this answer, but I strongly suspect that I've made too many assumptions about your data, in particular the constant nature of var2 and var3:</p> <pre><code>ddply(dat,.(permno,dte,var2,var3), function(x) { dcast(x,permno + dte + var2 + var3 ~ ttm,value.var = 'var1') }) permno dte var2 var3 20 30 1 123 2012-01-01 10 100 1 -1 2 124 2012-01-01 20 200 2 -2 </code></pre>