Likert grouping error in R

I am trying to use the grouping argument in the likert function, but I get the error:

lik <- likert(df2, grouping = df$CAR)

Error in sum(x) : invalid 'type' (character) of argument

      

Here's my simple code:

library(likert)

df<- fread("C:/R/temp/likert_test.csv", select = 1:6)
df <- as.data.frame(df)

col_names <- names(df[1:6])
df[,col_names] <- lapply(df[,col_names] , factor)

str(df)
'data.frame':   19331 obs. of  6 variables:
 $ CAR                                                     : Factor w/ 34 levels "Alfa Romeo","Audi",..: 4 4 4 4 3 3 3 3 4 4 ...
 $ E1.Overall Satisfaction                                 : Factor w/ 10 levels "1","2","3","4",..: 8 8 8 9 9 7 10 8 7 10 ...
 $ E2.Exterior Styling                                     : Factor w/ 10 levels "1","2","3","4",..: 9 8 8 10 8 4 10 8 7 10 ...
 $ E2.Overall Quality                                      : Factor w/ 10 levels "1","2","3","4",..: 8 8 7 10 10 8 10 8 8 10 ...
 $ E2.Interior Styling                                     : Factor w/ 10 levels "1","2","3","4",..: 9 6 9 10 9 8 9 8 7 10 ...
 $ E2.Quality Of Interior And Materials Used Inside The Car: Factor w/ 10 levels "1","2","3","4",..: 7 6 7 10 10 8 10 7 7 10 ...


df2 <- df[,2:5]

lik <- likert(df2, grouping = df$CAR)

      

+3


source to share


3 answers


This bug has been reported on Github ( https://github.com/jbryer/likert/issues/26 ). The solution is to download the package reshape

.



library(likert)
library(reshape)

# I created a sample. Please provide a sample like this from next time.
foo <- data.frame(car = rep(c("Toyota", "BMW", "Ford"), times = 5),
                  satisfaction = c(1,3,4,7,7,6,2,3,5,5,5,2,4,1,7),
                  quality = c(1,1,3,5,4,3,6,4,3,6,6,1,7,2,7))

# Convert all columns to factor
foo[1:3] <- lapply(foo[1:3], as.factor)

likert(foo[,c(2:3)], grouping = foo$car)

#   Group         Item  1  2  3  4  5  6  7
#1    BMW satisfaction 20  0 40  0 20  0 20
#2    BMW      quality 20 20  0 40  0 20  0
#3   Ford satisfaction  0 20  0 20 20 20 20
#4   Ford      quality 20  0 60  0  0  0 20
#5 Toyota satisfaction 20 20  0 20 20  0 20
#6 Toyota      quality 20  0  0  0 20 40 20

      

+5


source


In the latest likert, loading "reshape" no longer solves this problem.

To make it work, you need to detach the "reshape" from the package and load the reshape2 file.



detach('package:reshape')
library(reshape2)

      

+1


source


Hmm. I had the same question today. However, changing the boot didn't solve it for me. I am running R 3.2.2 on Windows 7.

#rerunning the above code
library(likert)
library(reshape)

# I created a sample. Please provide a sample like this from next time.
foo <- data.frame(car = rep(c("Toyota", "BMW", "Ford"), times = 5),
                  satisfaction = c(1,3,4,7,7,6,2,3,5,5,5,2,4,1,7),
                  quality = c(1,1,3,5,4,3,6,4,3,6,6,1,7,2,7))

# Convert all columns to factor
foo[1:3] <- lapply(foo[1:3], as.factor)

likert(foo[,c(2:3)], grouping = foo$car)

#####Results in
> library(likert)
Loading required package: ggplot2
Loading required package: xtable
> library(reshape)
> 
> # I created a sample. Please provide a sample like this from next time.
> foo <- data.frame(car = rep(c("Toyota", "BMW", "Ford"), times = 5),
+                   satisfaction = c(1,3,4,7,7,6,2,3,5,5,5,2,4,1,7),
+                   quality = c(1,1,3,5,4,3,6,4,3,6,6,1,7,2,7))
> 
> # Convert all columns to factor
> foo[1:3] <- lapply(foo[1:3], as.factor)
> 
> likert(foo[,c(2:3)], grouping = foo$car)

Error in fix.by(by.y, y) : 'by' must specify uniquely valid columns

      

0


source







All Articles