title: Print a frequency table of a factor with kable in rmarkdown
body: <p>I have a factor in R, that consists of the levels a, b and c. The data consists of 2 a's, one b and no c. I want to get an output like this (frequency of the elements according to the levels):</p>
  
  <pre><code>fac &lt;- factor(c("a", "b", "a"), levels=c("a", "b", "c"))
  tbl &lt;- table(fac)
  tbl
  
  ## fac
  ## a b c 
  ## 2 1 0
  </code></pre>
  
  <p>This should be printed with knitr/kable in a nice html table:</p>
  
  <pre><code>library(knitr)
  kable(tbl)
  </code></pre>
  
  <p>But here comes the error:</p>
  
  <pre><code>"Error in dn[[2L]] : subscript out of bounds".
  </code></pre>
  
  <p>I assume that there is an issue with the dimnames of the table:</p>
  
  <pre><code>attributes(tbl)
  ## $dim
  ## [1] 3
  ## 
  ## $dimnames
  ## $dimnames$fac
  ## [1] "a" "b" "c"
  ## 
  ## 
  ## $class
  ## [1] "table"
  </code></pre>
  
  <p>Is there any option to "repair" the dimnames for kable? I just want to print this "simple" table - maybe I am stuck with something easy?</p>
  
  <p>The usage of "table" with factors is described here: <a href="http://www.stat.berkeley.edu/~s133/factors.html" rel="nofollow">http://www.stat.berkeley.edu/~s133/factors.html</a></p>
  
  <p>I read a lot about the 'pander'-package in the recent days. If I print the table with pander, it works. Why? Should I just switch to pander?</p>
  
  <pre><code>pander(tbl)
  </code></pre>