ec_util_choice_to_long {echoice2}R Documentation

Convert a vector of choices to long format

Description

Converts a vector of choices into a long format data frame, where each row represents a single choice and contains the choice status for each alternative.

Usage

ec_util_choice_to_long(myvec, all_index)

Arguments

myvec

A vector of choices, where each element represents the index of the chosen alternative.

all_index

A vector of all the possible alternative indices.

Value

A tibble with columns 'x', 'task', and 'alt', where 'x' is a binary indicator of whether the alternative was chosen or not, 'task' is the task index, and 'alt' is the alternative index.

Examples

#There are 3 alternatives in this task. 
#Since there are 3 observations in myvec, there are 3 tasks total.
ec_util_choice_to_long(c(1, 2, 1), c(1, 2, 3))


[Package echoice2 version 0.2.4 Index]