I have a factor in R consisting of levels a, b and c. The data consists of 2 a, one b and no c. I want to get this output (frequency of elements according to levels):
fac <- factor(c("a", "b", "a"), levels=c("a", "b", "c"))
tbl <- table(fac)
tbl
This should be printed using knitr / kable in a good html table:
library(knitr)
kable(tbl)
But here an error occurs:
"Error in dn[[2L]] : subscript out of bounds".
I assume there is a problem with the table dimnames:
attributes(tbl)
#
#
#
#
#
#
#
#
#
#
Is there an option to "restore" dimnames for kable? I just want to print this “simple” table - maybe I'm stuck with something easy?
The use of a “table” with factors is described here: http://www.stat.berkeley.edu/~s133/factors.html
"" . pander, . ? pander?
pander(tbl)