tab_all: Tabulate all variables

Description Usage Arguments Value Author(s) Examples

View source: R/tab_all.R

Description

Tabulate all variables

Usage

1
2
3
4
tab_all(data, var = NULL, by = NULL, complete = FALSE,
  arrange.factor.by = "value", show.percentage = "column",
  show.na.percentage = TRUE, row.break.value = " ",
  trunc.length = 60, n.decimals = 0, plotit = FALSE)

Arguments

data

a data.frame

var

a character specifying the variable to tabulate, if set to NULL the first variable will be used

by

a character specifying the variable to stratify by, if set to NULL no stratification will be used

complete

a logical specifying whether to use all levels for factor variables

arrange.factor.by

a character with value either "level" or "value" describing how a factor variable should be ordered

show.percentage

a character either 'column' or 'row' or NULL to indicate whether to show percentages in output

show.na.percentage

a logical specifying whether to show percentages for NA values

row.break.value

a character specifying the value to use as row breaks

trunc.length

a numeric specifying the maximum character length to be shown in the output

n.decimals

a numeric specifying the number of decimal places to show

plotit

a logical specifying whether to plot the output

Value

either (1) a data.frame or (2) a list including a data.frame and a ggplot figure

Author(s)

Daniel Gardiner (daniel.gardiner@phe.gov.uk)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# set dummy data

set.seed(4)

data = data.frame(onset.date = sample(seq(as.Date("2017-01-01"), as.Date("2018-06-01"), 1), 200, replace = TRUE),
                  sex = factor(c("M", "M", "F", NA, NA), c("F", "M", "Unk")),
                  age = sample(c(0:100), 200, replace = TRUE),
                  conf = sample(c("Confirmed", "Probable", "Probable"), 200, replace = TRUE),
                  status = sample(c("Student", "Staff", NA), 200, replace = TRUE),
                  geog = sample(c("South", "North", NA), 200, replace = TRUE))

# apply function

tab_all(data, var = c("sex", "age", "onset.date", "geog"))

tab_all(data, var = c("sex", "age", "onset.date", "geog"), by = "conf")

# using dplyr syntax

data %>%
  select(conf, sex, onset.date, geog) %>%
  tab_all(by = "conf")

data %>%
  select(conf, sex, onset.date, geog) %>%
  tab_all(by = "conf",
          show.percentage = "row",
          row.break.value = "_____")

data %>%
  select(conf, sex, onset.date, geog) %>%
  tab_all(by = "conf",
          show.percentage = "row",
          plotit = TRUE)

DanielGardiner/EpiFunc documentation built on July 25, 2019, 10:53 p.m.