multi.split: Split a multiple choices variable in a series of binary...

View source: R/table.multi.R

multi.splitR Documentation

Split a multiple choices variable in a series of binary variables

Description

Split a multiple choices variable in a series of binary variables

Usage

multi.split(var, split.char = "/", mnames = NULL)

Arguments

var

variable to split

split.char

character to split at

mnames

names to give to the produced variabels. If NULL, the name are computed from the original variable name and the answers.

Details

This function takes as input a multiple choices variable where choices are recorded as a string and separated with a fixed character. For example, if the question is about the favourite colors, answers could be "red/blue", "red/green/yellow", etc. This function splits the variable into as many variables as the number of different choices. Each of these variables as a 1 or 0 value corresponding to the choice of this answer. They are returned as a data frame.

Value

Returns a data frame.

See Also

multi.table

Examples

v <- c("red/blue","green","red/green","blue/red")
multi.split(v)
## One-way frequency table of the result
multi.table(multi.split(v))

questionr documentation built on Feb. 16, 2023, 10:14 p.m.