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 in my dataset, so table()
removes that value from the frequency table. I would like it instead to present the value with a frequency of 0
. That is, given the following dataset
# Assume a 5pt Likert scale for ease of example
data <- c(1, 1, 2, 1, 4, 4, 5)
I would like to get the following frequency table without having to manually insert a column named 3
with the value 0
.
1 2 3 4 5
3 1 0 2 1
I'm new to R
, so maybe I've overlooked something basic, but I haven't come across a function or option that gives the desired result.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…