crosstab | R Documentation |
crosstab - outputs a cross table in format data frame >> Obsolete replaced by epitable
crosstab(data, var1, var2, missing = "always", extra = "None", decimals = 1)
data |
The data set to look at |
var1 |
Character string, colomn name of the first variable (the rows). Must be a 0/1 (numeric) or No/Yes (character) categorical variable (factors not supported yet). |
var2 |
Character string, colomn name of the second variable (the columns). Must be a 0/1 (numeric) or No/Yes (character) categorical variable (factors not supported yet). |
missing |
takes auguments 'no' to not show missing and 'always' to show missing (as for table()) |
extra |
What extra info you want. Current options "None", "Total" and "Percent". Default is "None". Feel free to add your own! |
decimals |
state how many decimal points you want to list for the output of any calculations. Default is 1 |
data <- data.frame(id = 1:10,
cases = c(rep(1,3), rep(0,7)),
vacc = sample(c(0,1), replace = TRUE, size = 10))
table(data$cases, data$vacc, useNA = "always")
crosstab(data,
var1 = "cases",
var2 = "vacc")
crosstab(data,
var1 = "cases",
var2 = "vacc",
missing = "no")
crosstab(data,
var1 = "cases",
var2 = "vacc",
extra = "Total")
crosstab(data,
var1 = "cases",
var2 = "vacc",
extra = "Percent")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.