library("papaja")
knitr::opts_chunk$set(echo = TRUE)
my_table <- 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[1, , drop = FALSE]
  , align = c("l", "r", "r")
  , caption = "0 Single row table."
  , note = "This table was created using apa_table()"
  , small = TRUE
  , placement = NULL
)
apa_table(
  my_table
  , align = c("l", "r", "r")
  , caption = "1 A small table with custom number formatting."
  , note = "This table was created using apa_table()"
  , font_size = "small"
  , digits = 3
  , format.args = list(decimal.mark = ",", big.mark = "")
)
apa_table(
  list(
    test = my_table
    , `moar test` = my_table
  )
  , align = c("l", "r", "r")
  , caption = "2 A tiny merged table (list of two) with added stub heading. Not escaped."
  , note = "This table was created using apa\\_table()"
  , added_stub_head = "Desciptives"
  , escape = FALSE
  , font_size = "tiny"
)
apa_table(
  list(
    test = my_table
    , `moar test` = my_table
  )
  , align = c("l", "r", "r")
  , caption = "2.25 A merged table (list of two) with table spanners."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
  , merge_method = "table_spanner"
)
var_labelled <- as.data.frame(my_table)
variable_label(var_labelled) <- c(speed = "$\\alpha$", dist = "$\\beta$")

apa_table(
  list(
    test = var_labelled
    , `moar test` = var_labelled
  )
  , align = c("l", "r", "r")
  , caption = "2.5 A merged table (list of two) with added stub heading and variable labels. Not escaped."
  , note = "This table was created using apa\\_table()"
  , added_stub_head = "Desciptives"
  , escape = FALSE
)
apa_table(
  list(
    test = my_table
  )
  , align = c("l", "r", "r")
  , caption = "3 A 'merged' table (list of one) with added stub heading."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
)
my_table2 <- my_table
rownames(my_table2) <- 1:nrow(my_table2)

apa_table(
  my_table2
  , align = c("l", "r", "r")
  , caption = "4 Test if simple row numbers are omitted from table."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
)
apa_table(
  list(A = my_table2, B = my_table2)
  , align = c("l", "r", "r")
  , caption = "5 Test if simple row numbers are omitted from merged table (list of two)."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
)
apa_table(
  list(A = my_table2[1:2, ], B = my_table2)
  , align = c("l", "r", "r")
  , caption = "5.25 Test if simple row numbers are omitted from merged table with unequal row numbers (list of two)."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
)
apa_table(
  list(A = cars[1:2, ], B = cars[3:6, ])
  , align = c("l", "r", "r")
  , caption = "5.25 Test if simple continued row numbers are omitted from merged table (list of two)."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
)
apa_table(
  list(A = cars[1:2, ], B = cars[5:7, ]
      )
  , align = c("l", "r", "r")
  , caption = "5.25 Test if simple discontinued row numbers are preserved from merged table(list of two)."
  , note = "This table was created using apa_table()"
  , added_stub_head = "Desciptives"
)
apa_table(
  my_table
  , align = c("l", "r", "r")
  , caption = "6 Test of column spanner and stub indenting."
  , note = "This table was created using apa_table()."
  , row.names = TRUE
  , added_stub_head = "Desciptives"
  , col_spanners = list(Measure = c(2, 3))
  , stub_indents = list(2:3)
)
my_table <- rbind(t(my_table), t(my_table), t(my_table))
rownames(my_table) <- 1:nrow(my_table)

apa_table(
  my_table
  , align = c("l", "r", "r")
  , caption = "7 Test of midurles and landscape mode and named stub indentation."
  , note = "This table was created using apa_table()."
  , added_stub_head = "Desciptives"
  , col_spanners = list(Measure = c(2, 3))
  , midrules = 4
  , stub_indents = list(c(1:2), Jo = c(4:6))
  , landscape = TRUE
)
my_table <- rbind(my_table, my_table, my_table, my_table, my_table, my_table, my_table)
rownames(my_table) <- 1:nrow(my_table)

apa_table(
  my_table
  , align = c("l", "r", "r")
  , caption = "8 A long table."
  , note = "This table was created using apa_table()."
  , added_stub_head = "Desciptives"
  , col_spanners = list(Measure = c(2, 3))
  , midrules = 4
  , stub_indents = list(c(1:2), Jo = c(4:6))
  , longtable = TRUE
)
apa_table(
  my_table
  , align = c("l", "r", "r")
  , caption = "9 A long table in landscape mode."
  , note = "This table was created using apa_table()."
  , added_stub_head = "Desciptives"
  , col_spanners = list(Measure = c(2, 3))
  , midrules = 4
  , stub_indents = list(c(1:2), Jo = c(4:6))
  , longtable = TRUE
  , landscape = TRUE
)
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
d.AD <- data.frame(treatment, outcome, counts)
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())

apa_table(
  apa_print(glm.D93)$table
  , align = "lrrrr"
  , escape = FALSE
)


Try the papaja package in your browser

Any scripts or data that you put into this service are public.

papaja documentation built on Oct. 30, 2024, 9:09 a.m.