knitr (version 1.4.1)

kable: Create tables in LaTeX, HTML, Markdown and reStructuredText

Description

This is a very simple table generator. It is simply 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, align, output = TRUE, 
    ...)

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 b
digits
the maximum number of digits for numeric columns (passed to round())
row.names
whether to include row names; by default, row names are included if they are neither NULL nor identical to 1:nrow(x)
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
output
whether to write out the output in the console
...
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.

See Also

Other R packages such as xtable and tables.

Examples

Run this code
kable(head(iris), format = "latex")
kable(head(iris), format = "html")
# 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)
# add some table attributes
kable(head(iris), format = "html", table.attr = "id="mytable"")
# reST output
kable(head(mtcars), format = "rst")
# no row names
kable(head(mtcars), format = "rst", row.names = FALSE)
# R Markdown/Github Markdown tables
kable(head(mtcars[, 1:5]), format = "markdown")
# Pandoc tables
kable(head(mtcars), format = "pandoc")
# save the value
x = kable(mtcars, format = "html", output = FALSE)
cat(x, sep = "\n")
# can also set options(knitr.table.format = 'html') so that the output is HTML

Run the code above in your browser using DataCamp Workspace