Learn R Programming

idefix (version 0.2.4)

Charbin: Character vector to binary vector.

Description

Transforms a character vector with responses into a binary vector. Each alternative in each choice set wil be either 0 or 1. If the alternative was not chosen 0, and 1 if it was. The function can be used for example in a shiny application to transform the response vector received from radioButtons into a numeric vector that can be used for estimation.

Usage

Charbin(resp, alts, n.alts, no.choice = FALSE)

Arguments

resp

String vector containing input responses

alts

String vector containing all possible alternatives. The order should be the same as the order of the design matrix.

n.alts

The number of alternatives per choice set.

no.choice

Logical value indicating whether a no.choice option is provided or not. The default = FALSE.

Value

A binary response vector with length equal to length(resp) * length(n.alts).

Details

The n.alts denotes the number of alternatives a respondent could choose from, without counting a possible no choice option.

If no.choice is TRUE the first alternative specified in alts will be treated as a no choice option. If the no choice option was chosen all alternatives are zero for that choice set.

Examples

Run this code
# NOT RUN {
# Observed Responses 
resp <- c("alt1", "alt3", "alt2", "no.choice", "alt1") 
# All possible alternatives 
alts <- c("no.choice", "alt1", "alt2", "alt3")
# 3 alternatives + no.choice 
Charbin(resp = resp, alts = alts, n.alts = 3, no.choice = TRUE)
# }

Run the code above in your browser using DataLab