R: Two-way frequency table between a multiple choices question...

cross.multi.table {questionr} | R Documentation

## Two-way frequency table between a multiple choices question and a factor

### Description

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.

### Usage

    cross.multi.table(df, crossvar, weights = NULL, digits = 1, freq = FALSE,
      tfreq = "col", n = FALSE, na.rm = TRUE, ...)

### Arguments

`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 `TRUE`, and freq is `TRUE`, display number of observations per row or column
`na.rm` | Remove any NA values in `crossvar`
`...` | arguments passed to `multi.table`

### Details

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.

### Value

Object of class table.

### See Also

`multi.table`, `multi.split`, `table`

### Examples

    ## 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)

[Package questionr version 0.6.3 Index]