1

I am new to R, and i am using the "likert" package to illustrate survey data. I have the following issue.

When i plot a likert-scale where all options are used, (the dataset contains observations for each of the 4 categories) i have no problem. But if no answers are present for one of the categories, i get the error:

item3 <- likert(comb2) Error in likert(comb2) : All items (columns) must have the same number of levels

I see the following option for the function 'likert': nlevels = length(levels(items[, 1]))) This might contain a solution, as the text says: "number of possible levels. Only necessary if there are missing levels."

However i dont know how to fill out the option.

My data looks like this:

str(comb2) 'data.frame': 1475 obs. of 2 variables:

$ Jeg er god til at bruge en computer (land) : Factor w/ 4 levels "a: Meget enig",..

$ Jeg er god til at bruge en computer (skole): Factor w/ 3 levels "a: Meget enig",..

The options are: "a: Meget enig" , "b: Lidt enig" , "c: Lidt uenig" , "d: Meget uenig" , Where one of the options are not present in one of the columns

Anders
  • 75
  • 1
  • 8

2 Answers2

3

I solved the issue, by using this command:

factor(var$col, levels=c(1:4), labels = c("a: Meget enig","b: Lidt enig","c: Lidt uenig", "d: Meget uenig"))

Thanks anyways!

s__
  • 9,270
  • 3
  • 27
  • 45
Anders
  • 75
  • 1
  • 8
3

There is another potential reason for this error which is quite counterintuitive: The same error message is also thrown when you use a tibble instead of a dataframe! I asked the package author to fix the error message or include the handling of tibbles - please upvote this feature request on Github.

So just transform your data explicitly into a dataframe with as.data.frame(your_data) and try again.

Otherwise, you can follow this tutorial given by the package author in the case of unused factor levels.

Agile Bean
  • 6,437
  • 1
  • 45
  • 53