green diod green diod - 1 year ago 71
R Question

r xtable and table of frequencies, printing rowwise

doesn't know at the moment how to print tables of frequencies from
. What I do now is I convert it to a dataframe and then I change the headings using
as needed:

dset <- data.frame(rpois(100, 1))
dset.print <-
colnames(dset.print) <- c("smth", "freq")

Now, what I'd like is to print this table rowwise (like the actual output of
with the headings at the front). I tried something like this

dset.print <- t(as.matrix(table(dset)))
dset.print <- cbind(c("smth", "freq"),

But this didn't exactly give what I wanted.

Answer Source

This looks pretty good if you're knitting to PDF. If you're knitting to MS Word or HTML, specify print(dset.xtab, type="html") You may not find the aesthetics of those as nice.

```{r xtable, echo=FALSE, message=FALSE, warning=FALSE, results='asis'}

dset <- data.frame(rpois(100, 1))

dset.print <-
dset.print <-[,1]), dset.print[,2])
names(dset.print) <- rep('', ncol(dset.print))
rownames(dset.print) <- c('smth', 'freq')

dset.xtab <- xtable(dset.print)


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download