How to use R for multiple select questions?

后端 未结 3 581
攒了一身酷
攒了一身酷 2021-02-04 19:03

I am trying to figure out how to analyze multiple select/multiple responses (i.e., \'select all that apply\') questions in a survey I recently conducted.

SPSS has nice c

3条回答
  •  你的背包
    2021-02-04 19:13

    I've not found anything that is quite as convenient as the multiple response sets in SPSS. However, you can create groups relatively easily based on common column names, and then use any of the apply() function or friends to iterate through each group. Here's one approach using adply() from the plyr package:

    library(plyr)
    set.seed(1)
    #Fake data with three "like" questions. 0 = non selected, 1 = selected
    dat <- data.frame(resp = 1:10,
                      like1 = sample(0:1, 10, TRUE),
                      like2 = sample(0:1, 10, TRUE),
                      like3 = sample(0:1, 10, TRUE)
                      )
    
    adply(dat[grepl("like", colnames(dat))], 2, function(x)
      data.frame(Count = as.data.frame(table(x))[2,2], 
            Perc = as.data.frame(prop.table(table(x)))[2,2]))
    #-----
         X1 Count Perc
    1 like1     6  0.6
    2 like2     5  0.5
    3 like3     3  0.3
    

提交回复
热议问题