Description Usage Arguments Author(s) Examples
Tabulate 2 variables
1 2 |
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 |
Daniel Gardiner (daniel.gardiner@phe.gov.uk)
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()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.