Formats matrices
and data.frames
to report them as tables according to APA guidelines
(6th edition).
apa_table(x, ...)# S3 method for apa_results_table
apa_table(x, escape = FALSE, ...)
# S3 method for matrix
apa_table(x, caption = NULL, note = NULL,
stub_indents = NULL, added_stub_head = NULL, col_spanners = NULL,
midrules = NULL, placement = "tbp", landscape = FALSE,
font_size = NULL, escape = TRUE, span_text_columns = TRUE, ...,
format.args = NULL)
# S3 method for list
apa_table(x, caption = NULL, note = NULL,
stub_indents = NULL, added_stub_head = NULL, col_spanners = NULL,
midrules = NULL, placement = "tbp", landscape = FALSE,
font_size = NULL, escape = TRUE, merge_method = "indent",
span_text_columns = TRUE, ..., format.args = NULL)
# S3 method for data.frame
apa_table(x, caption = NULL, note = NULL,
stub_indents = NULL, added_stub_head = NULL, col_spanners = NULL,
midrules = NULL, placement = "tbp", landscape = FALSE,
font_size = NULL, escape = TRUE, span_text_columns = TRUE, ...,
format.args = NULL)
Object to print, can be matrix
, data.frame
, or list
. See details.
Arguments passed on to knitr::kable
An R object, typically a matrix or data frame.
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 the global option knitr.table.format
. If
format
is a function, it must return a character string.
Maximum number of digits for numeric columns, passed to
round()
. This can also be a vector of length ncol(x)
, to set
the number of digits for individual columns.
Logical: whether to include row names. By default, row names
are included if rownames(x)
is neither NULL
nor identical to
1:nrow(x)
.
A character vector of column names to be used in the table.
Column alignment: a character vector consisting of 'l'
(left), 'c'
(center) and/or 'r'
(right). By default or if
align = NULL
, numeric columns are right-aligned, and other columns
are left-aligned. If length(align) == 1L
, the string will be
expanded to a vector of individual letters, e.g. 'clc'
becomes
c('c', 'l', 'c')
, unless the output format is LaTeX.
The table caption.
The table reference label. By default, the label is obtained
from knitr::opts_current$get('label')
.
A list of arguments to be passed to format()
to format table values, e.g. list(big.mark = ',')
.
Boolean; whether to escape special characters when producing
HTML or LaTeX tables. When escape = FALSE
, you have to make sure
that special characters will not trigger syntax errors in LaTeX or HTML.
Logical. If TRUE
special LaTeX characters, such as %
or _
, in
column names, row names, caption, note and table contents are escaped.
Character. Caption to be printed above the table.
Character. Note to be printed below the table.
List. A named list of vectors that contain indeces of the rows to indent. The name of each list element containing the vector is used as title for indented sections.
Character. Used as stub head (name of first column) if row.names = TRUE
is passed to kable
; ignored if row names are omitted from the table.
List. A named list of vectors of length 2 that contain the first and last column to span. The name of each list element containing the vector is used as grouping column name. Ignored in MS Word documents.
Numeric. Vector of line numbers in table (not counting column headings) that should be followed by a horizontal rule; ignored in MS Word documents.
Character. Indicates whether table should be placed at the exact location (h
),
at the top (t
), bottom (b
), or on a separate page (p
). Arguments can be combined
to indicate order of preference (htb
); ignored when longtable = TRUE
, landscape = TRUE
,
and in MS Word documents.
Logical. If TRUE
the table is printed in landscape format; ignored in MS Word
documents.
Character. Font size to use for table contents (can be tiny
, scriptsize
, footnotesize
, small
, normalsize
(default), large
, Large
, LARGE
, huge
, Huge
). Ignored in MS Word documents.
Logical. If TRUE
tables span across text columns
in two-column PDF documents (e.g. when setting classoption: jou
).
Ignored in other documents.
List. A named list of arguments to be passed to printnum
to format numeric values.
Character. Determines how to merge tables if x
is a list
. Can be either
indent
or table_spanner
.
When using apa_table
, the type of the output (LaTeX or MS Word) is determined automatically
by the rendered document type. If no rendering is in progress the output default is LaTeX.
The chunk option of the enveloping chunk has to be set to results = "asis"
to ensure the table
is rendered, otherwise the table-generating markup is printed.
If x
is a list
, all list elements are merged by columns into a single table with
the first column giving the names of the list elements elements.
# NOT RUN {
my_table <- t(apply(cars, 2, function(x) # Create data
round(c(Mean = mean(x), SD = sd(x), Min = min(x), Max = max(x)), 2)
))
apa_table(
my_table
, align = c("l", rep("r", 3))
, caption = "A summary table of the cars dataset."
)
apa_table(
cbind(my_table, my_table)
, align = c("l", rep("r", 8))
, caption = "A summary table of the cars dataset."
, note = "This table was created using apa\\_table()"
, added_stub_head = "Variables"
, col_spanners = list(`Cars 1` = c(2, 5), `Cars 2` = c(6, 9))
)
apa_table(
list(`Cars 1` = my_table, `Cars 2` = my_table)
, caption = "A summary table of the cars dataset."
, added_stub_head = "Variables"
)
# }
Run the code above in your browser using DataLab