Description Usage Arguments Value Author(s) Examples
Tabulate all variables
1 2 3 4 |
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 |
either (1) a data.frame or (2) a list including a data.frame and a ggplot figure
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 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.