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

  1. If your data are in a long format. you can pass reshape2 formula for casting the data. If the data
  2. If your data are in a wide format, you can pass information to the cols and rows argument to specify and the sep to let tisch know alon.
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

Alt text

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 = " ")

Adding elements

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:

1. Getting started: Setting up the tisch object

Wide format data frames

library(tisch)

tt <- tisch(mm, row = c(1,2), cols = c(3,4), sep = "_")

Long format data frames

library(tisch)

tt <- tisch(mm, x1 + x2 ~ x3 + x4)
tt

2. Convert

After setting up the tisch object, it is time to convert it into At the moment, tisch only provides a converter for LaTeX documents.

LaTeX converter

to_tex() function. position (t, b, p, h)

to_tex(tt)

Annotations

caption(), footnote() and label()

tt <- tt + caption("asd") + footnote("asd") + label("tab:mm")
to_tex(tt)

Theming

tt + theme(textsize = "10", background_color = "#00000", )
to_tex(tt)

Row styles

fullrow()

looserow()

spanrow()

steprow() The idendation of each level can be controlled through the indent argument.

Grid

Rules

Statistical models

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)

Outlook



crubba/tisch documentation built on May 14, 2019, 12:06 p.m.