# toy example
# brands - multiple response question
# Which brands do you use during last three months? 
set.seed(123)
brands = t(replicate(20,sample(c(1:5,NA),4,replace = FALSE)))
# score - evaluation of tested product
score = sample(-1:1,20,replace = TRUE)
var_lab(brands) = "Used brands"
val_lab(brands) = make_labels("
                              1 Brand A
                              2 Brand B
                              3 Brand C
                              4 Brand D
                              5 Brand E
                              ")
var_lab(score) = "Evaluation of tested brand"
val_lab(score) = make_labels("
                             -1 Dislike it
                              0 So-so
                              1 Like it    
                             ")
# percentage of used brands
colMeans(dichotomy(brands))
# percentage of brands within each score
cro_mean(dichotomy(brands), score)
# the same as
cro_cpct(brands, score)
# percentage of brands within each score - same numbers
aggregate(dichotomy(brands) ~ f(score), FUN = mean)
# or, same result in another form
by(dichotomy(brands), f(score), FUN = colMeans)
# customer segmentation by used brands
kmeans(dichotomy(brands),3)
# model of influence of used brands on evaluation of tested product 
summary(lm(score ~ dichotomy(brands)))
# prefixed data.frame 
dichotomy_df(brands, prefix = "brand_")
Run the code above in your browser using DataLab