tab_2vars: Tabulate 2 variables

Description Usage Arguments Author(s) Examples

View source: R/tab_2vars.R

Description

Tabulate 2 variables

Usage

1
2
tab_2vars(data, row.var = NULL, col.var = NULL, complete = TRUE,
  include.row.total = TRUE, include.col.total = TRUE)

Arguments

data

a data.frame

row.var

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

complete

a logical specifying whether to use all levels for factor variables

include.row.total

a logical specifying whether to include row totals

include.col.total

a logical specifying whether to include column totals

cols.var

a character specifying the variable to tabulate along columns, if set to NULL the second variable will be used

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
# set dummy data

set.seed(4)

data = data.frame(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")),
                  conf = sample(c("Confirmed", "Probable", "Probable"), 200, replace = TRUE),
                  status = sample(c("Student", "Staff", NA), 200, replace = TRUE),
                  geog = sample(c("South", "North"), 200, replace = TRUE))

# apply function

tab_2vars(data, row.var = "sex", col.var = "conf")

# using dplyr syntax

data %>%
select(sex, conf) %>%
  tab_2vars()

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