apa_table | R Documentation |
Formats matrices and data frames to report them as tables in R Markdown documents according to APA guidelines.
apa_table(x, ...)
## Default S3 method:
apa_table(x, ...)
## S3 method for class 'apa_results_table'
apa_table(x, escape = FALSE, ...)
## S3 method for class 'apa_results'
apa_table(x, ...)
## S3 method for class '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 class '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 class '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
)
x |
Object to print, either a |
... |
Arguments passed on to
|
escape |
Logical. If |
caption |
Character. Caption to be printed above the table. |
note |
Character. Note to be printed below the table. |
stub_indents |
List. A named list of vectors that contain indices of rows to indent. The name of each list element containing the vector is used as title for indented sections. |
added_stub_head |
Character. Used as stub head (name of first column)
if |
col_spanners |
List. A named list of vectors of length 2 that contain the indices of the first and last column to span. The name of each list element is used as grouping column name. Currently ignored in Word documents. |
midrules |
Numeric. Vector of line numbers in table (not counting column headings) that should be followed by a horizontal rule; currently ignored in Word documents. |
placement |
Character. Indicates whether table should be placed, for
example, at the current location ( |
landscape |
Logical. If |
font_size |
Character. Font size to use for table contents (can be
|
span_text_columns |
Logical. If |
format.args |
List. A named list of arguments to be passed to
|
merge_method |
Character. Determines how to merge tables if |
When using apa_table
, the type of the output (LaTeX or Word) is
determined automatically by the rendered document type. In interactive R
session the output defaults to LaTeX.
If x
is a list
, all list elements are merged by columns into a single
table and the names of list elements are added according to the setting of
merge_method
.
By default, the width of the table is set to accommodate its contents. In
some cases, this may cause the table to exceed the page width. To address
this, tables can be rotated 90 degrees by setting langscape = TRUE
or,
by explicitly using "paragraph columns" with fixed column widths, such
that the contents is automatically broken into multiple lines. For
example, set align = "lm{5cm}l"
to limit the second column to a width of
5 cm. Similarly, to space columns equally use
align = paste0("m{", 1/(ncol(x) + 1), "\\linewidth}")
Note that placement options are not supported in appendices of apa6
documents and will be printed to the document. To omit the printed options
set placement = NULL
.
A character vector of the table source code of class knit_asis
, see
knitr::asis_output()
.
knitr::kable()
, apa_num()
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"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.