title: How to convert a table into a data.table
body: <p>If, for some reason, a base R (two dimensional) <code>table</code> object comes along in your R workflow, what is the best (concise, readable, efficient) way to convert it to a <code>data.table</code> while keeping its dimension structure?</p>
  
  <p><em>Example data</em>:</p>
  
  <pre><code>set.seed(1)
  tab &lt;- structure(
    sample(0:1, size = 15, replace = TRUE), 
    .Dim = c(5,3), 
    .Dimnames = list(
      Pr = c("P1", "P2", "P3", "P4", "P9"), 
      Tr = c("T1", "T2", "T3")
    ), 
    class = "table"
  )
  </code></pre>
  
  <p><em>Example of failed attempts</em></p>
  
  <pre><code>setDT(tab)
  # Error in setDT(tab) : 
  #   Argument 'x' to 'setDT' should be a 'list', 'data.frame' or 'data.table'
  as.data.table(tab) # same data.table(tab), *could* be fixed with dcast()
  #     Pr Tr N
  #  1: P1 T1 0
  #  2: P2 T1 0
  #  3: P3 T1 1
  #  4: P4 T1 1
  #  5: P9 T1 0
  #  6: P1 T2 1
  #  7: P2 T2 1
  #  8: P3 T2 1
  #  9: P4 T2 1
  # 10: P9 T2 0
  # 11: P1 T3 0
  # 12: P2 T3 0
  # 13: P3 T3 1
  # 14: P4 T3 0
  # 15: P9 T3 1
  </code></pre>