comma2mat: Convert comma-separated lists of selections to a...

Description Usage Arguments Examples

View source: R/comma-sep-to-matrix.R

Description

Converts a variable containing list of selections, e.g. 1,4,10 to a list of variables, e.g. V1, V2, ..., V10, containing TRUE of FALSE indicating whether the corresponding item was selected. BUG: The function may fail mysteriously if one of the 'inputs' is not a number between 1 and the maximum number.

Usage

1
comma2mat(x, name = "Q", sep = ",")

Arguments

x

variable to convert

sep

(default ',') separator between numbers

(default

'Q') name for new variable, which will be followed by numbers to identify each question.

Examples

1
2
3
4
5
df <- data.frame(id = 1:4,
     ans = c('1,2,3','5,2,1,4','',NA))
df
df <- cbind(df,comma2mat(df$ans,"Ques."))
df    

gmonette/HG documentation built on May 17, 2019, 7:25 a.m.