How to use R for multiple select questions?

后端 未结 3 582
攒了一身酷
攒了一身酷 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:25

    multfreqtable(data_set, "Banner")
    multfreqtable = function(data, question.prefix) {
      z = length(question.prefix)
      temp = vector("list", z)
    
      for (i in 1:z) {
        a = grep(question.prefix[i], names(data))
        b = sum(data[, a] != 0)
        d = colSums(data[, a] != 0)
        e = sum(rowSums(data[,a]) !=0)
        f = as.numeric(c(d, b))
        temp[[i]] = data.frame(question = c(sub(question.prefix[i], 
                                                "", names(d)), "Total"),
                               freq = f,
                               percent_response = (f/b)*100,
                               percent_cases = (f/e)*100 )
        names(temp)[i] = question.prefix[i]
      }
      temp
    }
    

    does a very good job of giving you numbers, percentages at the number of cases level and percentage at the number of responses level. Perfect for analyzing Multi-Response Questions

提交回复
热议问题