Learn R Programming

papaja (version 0.1.0.9655)

apa_table: Prepare table for printing

Description

Formats matrices and data.frames to report them as tables according to APA guidelines (6th edition).

Usage

apa_table(x, caption = NULL, note = NULL, stub_indents = NULL,
  added_stub_head = NULL, col_spanners = NULL, midrules = NULL,
  placement = "tbp", landscape = FALSE, small = FALSE, escape = NULL,
  format.args = NULL, ...)

apa_table.latex(x, caption = NULL, note = NULL, col_spanners = NULL, midrules = NULL, placement = "tbp", landscape = FALSE, small = FALSE, ...)

apa_table.word(x, caption = NULL, note = NULL, ...)

Arguments

x

Object to print, can be matrix, data.frame, or list. See details.

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 indeces of the 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 row.names = TRUE is passed to kable; ignored if row names are omitted from the table.

col_spanners

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.

midrules

Numeric. Vector of line numbers in table (not counting column headings) that should be followed by a horizontal rule; ignored in MS Word documents.

placement

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.

landscape

Logical. If TRUE the table is printed in landscape format; ignored in MS Word documents.

small

Logical. If TRUE the font size of the table content is reduced.

escape

Logical. If TRUE special LaTeX characters, such as % or _, in column names, row names, caption, note and table contents are escaped. Default is TRUE if target document format is PDF.

format.args

List. A named list of arguments to be passed to printnum to format numeric values.

...

Further arguments to pass to kable.

Details

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.

See Also

kable, printnum

Examples

Run this code
# 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