title: R: Dimension names in tables and multi-dimensional arrays
body: <p>Since a function that I use requires a table object as parameter, I would like to convert a multidimensional array to a table, but I have problems with dimension names.</p>
  
  <p>As specified in the help file of <code>as.table</code>, the <code>dnn</code> parameter should contain dimnames names.</p>
  
  <pre><code>dnn … the names to be given to the dimensions in the result (the dimnames names).
  </code></pre>
  
  <p>But even when specifying <code>dnn</code>, my tables produced by <code>as.table</code> have no dimension names.</p>
  
  <p>The following code illustrates my problem.</p>
  
  <pre><code>&gt;test &lt;- table(c("a","b","c","c","c"),c("1","2","3","2","2"),dnn=c("letters","numbers"))
  &gt;test 
  
            numbers
  letters 1 2 3
        a 1 0 0
        b 0 1 0
        c 0 2 1
  
  # this works perfectly
  </code></pre>
  
  <p>now try the same when constructing the table from an array:</p>
  
  <pre><code>&gt;my2dimdata &lt;- array(c(1,0,0,0,1,2,0,0,1),dim=c(3,3),
                      dimnames=list(c("a","b","c"),
                                    c("1","2","3")))
  &gt;my2dimdata
  
    1 2 3
  a 1 0 0
  b 0 1 0
  c 0 2 1
  
  # the array as expected
  
  &gt;my2dimtable &lt;- as.table(my2dimdata,dnn=c("letters","numbers"))
  &gt;my2dimtable
  
    1 2 3
  a 1 0 0
  b 0 1 0
  c 0 2 1
  
  # there are no dimnames
  </code></pre>