title: reshape from wide to long, simple data.table issue
body: <p>I know there must be a one-line <code>data.table</code> solution for this, probably with <code>dcast</code>, but I can't figure it out.</p>
  <p>I have data like this:</p>
  <pre><code>library(data.table)
  data1 &lt;- data.table(
    id = seq(1:5),
    code = c(&quot;A&quot;,&quot;A&quot;,&quot;B&quot;,&quot;A&quot;,&quot;B&quot;),
    date = as.Date( c(&quot;2021-08-11&quot;,&quot;2021-01-05&quot;,&quot;2021-02-18&quot;,&quot;2021-02-13&quot;,&quot;2021-12-13&quot; ))
  )
  data2 &lt;- data.table(
    id = seq(1:5),
    code = c(&quot;B&quot;,&quot;B&quot;,&quot;A&quot;,&quot;B&quot;,&quot;A&quot;),
    date = as.Date( c(&quot;2021-08-13&quot;,&quot;2021-01-05&quot;,&quot;2021-02-19&quot;,&quot;2021-02-14&quot;,&quot;2021-12-13&quot; ))
  )
  data3 &lt;- rbind(data1, data2)
  
  </code></pre>
  <p>I simply wish to reshape to a wide format like this</p>
  <pre><code>data_want &lt;- data.table(
    id = seq(1:5),
    code1 = c(&quot;A&quot;, &quot;A&quot;,&quot;B&quot;,&quot;A&quot;,&quot;B&quot;),
    data1 = c(&quot;2021-08-11&quot;, &quot;2021-01-05&quot;,&quot;2021-02-18&quot;,&quot;2021-02-13&quot;,&quot;2021-12-13&quot;),
    code2 = c(&quot;B&quot;, &quot;B&quot;,&quot;A&quot;,&quot;B&quot;,&quot;A&quot;),
    data2 = c(&quot;2021-08-13&quot;, &quot;2021-01-05&quot;,&quot;2021-02-19&quot;,&quot;2021-02-14&quot;,&quot;2021-12-13&quot;)
  )
  
  </code></pre>
  <p>How to do it with <code>dcast</code>?</p>