# toy example
set.seed(123)
# score - evaluation of tested product
score = sample(-1:1,20,replace = TRUE)
var_lab(score) = "Evaluation of tested brand"
val_lab(score) = c("Dislike it" = -1,
                   "So-so" = 0,
                   "Like it" = 1    
                   )
# frequency of product scores                                      
fre(score)
# brands - multiple response question
# Which brands do you use during last three months? 
brands = t(replicate(20,sample(c(1:5,NA),4,replace = FALSE)))
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
                              ")
# percentage of used brands
fre(brands)
# percentage of brands within each score
cro(brands, score)
aggregate(dichotomy(brands) ~ f(score), FUN = mean)
# 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)))
## make labels from text copied from questionnaire
age = c(1, 2, 1, 2)
val_lab(age) = make_labels("
 1. 18 - 26
 2. 27 - 35
")
f(age)
# or, if in original codes is on the right side
products = 1:8
val_lab(products) = ml_right("
 Chocolate bars    1
 Chocolate sweets (bulk)	2
 Slab chocolate(packed)	3
 Slab chocolate (bulk)	4
 Boxed chocolate sweets	5
 Marshmallow/pastilles in chocolate coating	6
 Marmalade in chocolate coating	7
 Other	8
")
f(products)
Run the code above in your browser using DataLab