hierarchical table, HTML tables are a standard way to display tabular information online. Getting HTML table data into R is fairly straightforward with the `` function of the tisch package.
library(reshape2) names(ChickWeight) <- tolower(names(ChickWeight)) chick_m <- melt(ChickWeight, id = 2:4, na.rm = TRUE)
Generating a table follows a two-step procedure. First, users set up a tisch object using the tisch() function. At a bare minimum, tisch() requires to pass the name of the original data frame. If the data exhibit hierarchical structure and users wish to have this structure represented in the table then they need to. long format
library(tisch) tt <- tisch(chick_m, diet + chick ~ time)
The second step is converting the tisch object into the desired presentation format. Presently, tisch only has a single converter for LaTeX documents to_tex(). Future versions may involve other convertes, e.g. for html.
textable <- to_tex(tt)
write_tisch(x = textable, filename = "~/mytable.tex")
This generates the following table
library(reshape2) tips2 <- tips[, c("day", "time", "sex", "smoker", "tip")] tips2$tip <- formatC(tips2$tip, digits = 2)
tt2 <- tisch(tips2, day + time ~ sex + smoker, reorder = TRUE, fun.aggregate = function(x) mean(as.numeric(x))) gg <- to_tex(tt2)
dcast(tips2, day + time ~ sex + smoker, fun.aggregate = function(x) mean(as.numeric(x)), fill = " ")
such as a caption, footnotes, label and so on.
data(asd) head()
tt <- tisch(, ) + caption("asd") + footnote("asd") + theme( row_style = ragged(indent = 0.25), text_size = "10pt" ) to_tex(tt, position = "t")
On the column dimension, the are two styles:
library(tisch) tt <- tisch(mm, row = c(1,2), cols = c(3,4), sep = "_")
library(tisch) tt <- tisch(mm, x1 + x2 ~ x3 + x4)
tt
After setting up the tisch object, it is time to convert it into At the moment, tisch only provides a converter for LaTeX documents.
to_tex()
function. position (t, b, p, h)
to_tex(tt)
caption()
, footnote()
and label()
tt <- tt + caption("asd") + footnote("asd") + label("tab:mm") to_tex(tt)
tt + theme(textsize = "10", background_color = "#00000", ) to_tex(tt)
fullrow()
looserow()
spanrow()
steprow() The idendation of each level can be controlled through the indent argument.
Since both packages rely on the philosophy of tidy data, tisch works great with output generated by broom. Unlike stargazer, memisc's mtable or apstable, tisch provides no ready-make wrapper around standard statistical objects. You need to assemble those objects yourself and cast the information into a long data frame. I illustrate this approach with two regression models for
library(broom) library(dplyr) ddata <- group_by() stout <- summarise()
conventional
mtab <- tisch(stout, block + var + stat ~ depvar + mtype) + caption("Modelling ") + footnote("asd") theme( row_style = looserow() ) to_tex(mtab)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.