Include zero frequencies in frequency table for Likert data

前端 未结 3 1962
花落未央
花落未央 2020-12-16 03:36

I have a dataset with responses to a Likert item on a 9pt scale. I would like to create a frequency table (and barplot) of the data but some values on the scale never occur

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 03:53

    EDIT:

    tabular produces frequency tables while table produces contingency tables. However, to get zero frequencies in a one-dimensional contingency table as in the above example, the below code still works, of course.


    This question provided the missing link. By converting the Likert item to a factor, and explicitly specifying the levels, levels with a frequency of 0 are still counted

    data <- factor(data, levels = c(1:5))
    table(data)
    

    produces the desired output

提交回复
热议问题