dichotomize {classicaltest} | R Documentation |
Dichotomize data
Description
Converts a matrix or data frame into a dichotomized data frame. Where each possible category is assigned a 1 or a 0.
Usage
dichotomize(x, id = NULL, categories = NULL, NAasNA = TRUE, sortbyItem = FALSE)
Arguments
x |
a data frame or matrix. |
id |
a vector of unique values indicating the ids of the cases.
If |
categories |
a vector indicating all possible categories.
If |
NAasNA |
a logical value indicating if NAs should be kept
as NAs. If |
sortbyItem |
a logical value indicating if the resulting data frame
should be order by item names, on the contrary, by ids.
Default is |
Value
A data frame with columns for the ids, the item names and all the possible item categories, where 1s mean the person answered that category for that item, and 0s mean the contrary.
Examples
data(dichodata)
# Dichotomize with all present categories
ex1 <- dichotomize(dichodata, categories = NULL)
head(ex1)
# Dichotomize with fixed set of categories
ex2 <- dichotomize(dichodata, categories = c('A','B','C','D'))
head(ex2)
# Dichotomize with NAs as 0s
ex3 <- dichotomize(dichodata, NAasNA = FALSE)
head(ex3)