cross.multi.table | R Documentation |
This function allows to generate a two-way frequency table from a multiple choices question and a factor. The question's answers must be stored in a series of binary variables.
cross.multi.table( df, crossvar, weights = NULL, digits = 1, freq = FALSE, tfreq = "col", n = FALSE, na.rm = TRUE, ... )
df |
data frame with the binary variables |
crossvar |
factor to cross the multiple choices question with |
weights |
optional weighting vector |
digits |
number of digits to keep in the output |
freq |
display percentages |
tfreq |
type of percentages to compute ("row" or "col") |
n |
if |
na.rm |
Remove any NA values in |
... |
arguments passed to |
See the multi.table
help page for details on handling of the multiple
choices question and corresponding binary variables.
If freq
is set to TRUE, the resulting table gives the columns percentages
based on the contingency table of crossvar in the respondants population.
Object of class table.
multi.table
, multi.split
, table
## Sample data frame set.seed(1337) sex <- sample(c("Man","Woman"),100,replace=TRUE) jazz <- sample(c(0,1),100,replace=TRUE) rock <- sample(c(TRUE, FALSE),100,replace=TRUE) electronic <- sample(c("Y","N"),100,replace=TRUE) weights <- runif(100)*2 df <- data.frame(sex,jazz,rock,electronic,weights) ## Two-way frequency table on 'music' variables by sex cross.multi.table(df[,c("jazz", "rock","electronic")], df$sex, true.codes=list("Y")) ## Column percentages based on respondants cross.multi.table(df[,c("jazz", "rock","electronic")], df$sex, true.codes=list("Y"), freq=TRUE) ## Row percentages based on respondants cross.multi.table(df[,c("jazz", "rock","electronic")], df$sex, true.codes=list("Y"), freq=TRUE, tfreq="row", n=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.