title: How to convert a matrix into a data.table in R
body: <p>I have this data which is basically a matrix but is in data.table format:</p>
  
  <p>Lets call this matA:</p>
  
  <pre><code>Date    compA compB compC 
  200101      1     2     3 
  200102      2     4     1    
  </code></pre>
  
  <p>How do I make the matrix into a database type in data.table?</p>
  
  <p>Lets call this dataset dtB:</p>
  
  <pre><code>Date    Company    Data
  200101    compA       1
  200101    compB       2
  200101    compC       3
  200102    compA       2
  200102    compB       4
  200102    compC       1
  </code></pre>
  
  <p>I have thought about a very stupid way to make a list of companies:</p>
  
  <pre><code>comp= as.data.table(c("compA", "compB", "compC"))
  date= as.data.table(rep(matA[1,1],3))
  data= as.data.table(matA[1,])
  
  dtb= date[,Company := comp]
  dtb= dtb[, Data := data]
  </code></pre>
  
  <p>And obviously I can at most get the data in date 200101. To get 200102, I write a for loop. Then, merge both 200101 and 200102 into dtB according to the colnames.</p>
  
  <p>Is there a clever way to do this in data.table?
  Many thanks</p>