Description Usage Arguments Details See Also
This function makes it a little more convenient to print a data frame
as a nicely-formatted table in a knitted PDF. Use this function in a
chunk with the results="asis"
option set. The default values
should be enough to get along with when you're starting out, so you
can simply use print_tabular(x)
.
1 2 3 | print_tabular(x, digits = 0, alignment = paste(ifelse(sapply(x, is.numeric),
"r", "l"), collapse = ""), include.colnames = T, floating = F,
caption = NULL, label = NULL)
|
x |
A data frame. Row names are ignored. Other objects must be
converted manually. To print a two-way contingency table |
digits |
The number of decimal places to keep for numbers. Numbers are rounded to integers by default. |
alignment |
A string specifying column formats. |
include.colnames |
Logical: should the |
floating |
Logical. If |
caption |
Only applied to floating tables. Set to |
label |
Only applied to floating tables. The LaTeX label for
the table. Should be letters, hyphens, and colons only, with no
spaces. If the label is, say, |
It is not as easy as it should be to format tabular data nicely
in R markdown. Your R data structure has to be converted
into LaTeX commands for typesetting a table. This is not a
profound computational challenge, but it involves a bunch of
fiddly LaTeX parameters. The R package that helps with this,
xtable
, is itself fiddly and a bit confusing.
This function is meant to simply matters somewhat.
Unlike the xtable
function, the alignment
parameter here must always be given as a single string. Row names are
never used, so the number of columns to specify is the same as the
number of columns in the data frame.
To typeset successfully, the resulting LaTeX requires the
booktabs
and longtable
packages to be installed.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.