# kable

From knitr v1.7
0th

Percentile

##### Create tables in LaTeX, HTML, Markdown and reStructuredText

This is a very simple table generator. It is simple by design. It is not intended to replace any other R packages for making tables.

##### Usage
kable(x, format, digits = getOption("digits"), row.names = NA, col.names = colnames(x),
align, caption = NULL, ...)
##### Arguments
x
an R object (typically a matrix or data frame)
format
a character string; possible values are latex, html, markdown, pandoc, and rst; this will be automatically determined if the function is called within knitr; it can also be set in
digits
the maximum number of digits for numeric columns (passed to round()); it can also be a vector of length ncol(x) to set the number of digits for individual columns
row.names
a logical value indicating whether to include row names; by default, row names are included if rownames(x) is neither NULL nor identical to 1:nrow(x)
col.names
a character vector of column names to be used in the table
align
the alignment of columns: a character vector consisting of 'l' (left), 'c' (center) and/or 'r' (right); by default, numeric columns are right-aligned, and other columns are left-aligned; if align = NULL,
caption
the table caption
...
other arguments (see examples)
##### Value

• A character vector of the table source code. When output = TRUE, the results are also written into the console as a side-effect.

##### Note

The tables for format = 'markdown' also work for Pandoc when the pipe_tables extension is enabled (this is the default behavior for Pandoc >= 1.10).

When using this function inside a knitr document (e.g. R Markdown or R LaTeX), you will need the chunk option results='asis'.

##### References

See https://github.com/yihui/knitr-examples/blob/master/091-knitr-table.Rnw for some examples in LaTeX, but they also apply to other document formats.

Other R packages such as xtable and tables for HTML and LaTeX tables, and ascii and pander for different flavors of markdown output and some advanced features and table styles.

• kable
##### Examples
kable(head(iris), format = "latex")
kable(head(iris), format = "latex", caption = "Title of the table")
kable(head(iris), format = "html", caption = "Title of the table")
# use the booktabs package
kable(mtcars, format = "latex", booktabs = TRUE)
# use the longtable package
kable(matrix(1000, ncol = 5), format = "latex", digits = 2, longtable = TRUE)
kable(head(iris), format = "html", table.attr = "id="mytable"")
# reST output
# no row names
kable(head(mtcars), format = "rst", row.names = FALSE)
# R Markdown/Github Markdown tables
# can also set options(knitr.table.format = 'html') so that the output is HTML