R Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 5, 3

4.5k views Asked by At

So I'm using sjp.likert function from de 'sjPlot' package, to make a series of plots of different dataframes in which their columns correspond to different questions that follow a likert format.

The exact dataframe is reproduced below:

col_1 <- c(2,1,1,5)
col_2 <- c(2,1,1,2)
col_3 <- c(2,1,1,2)
col_4 <- c(2,1,1,2)
col_5 <- c(2,1,1,5)

df <- as.data.frame(cbind(col_1,col_2,col_3,col_4,col_5))

Following the instructions of the 'sjPlot' package, I gave labels to the questions as well as to the possible answers(value labels).

question.labels <- c("Las personas de mi Equipo están calificadas adecuadamente para desempeñar su trabajo",
"Mi equipo es eficiente para solucionar problemas sin perder tiempo en encontrar culpables",
 "Mi área busca formas de hacer los procesos de manera inteligente y eficiente", 
 "El ambiente en mi área es generalmente bueno", 
 "En mi Equipo tenemos una dinámica de trabajo que permite nuestro mejor desempeño")

value.labels <- c("strongly agree", "agree", "disagree", "strongly disagree",
  "neither agree or disagree")

Then I use the sjp.likert function to produce the plot:

sjp.likert(df, axisLabels.y = question.labels, legendLabels = value.labels)

But I get the following error:

 Error in data.frame(..., check.names = FALSE) :    arguments imply differing number of rows: 5, 3

While with the following dataframe there is no problem:

col_a <- c(2,3,1,2,2,1)
col_b <- c(2,4,2,5,2,2)
col_c <- c(2,3,2,2,2,2)
col_d <- c(2,2,1,2,2,1)
col_e <- c(3,5,1,2,2,1)

df2 <- cbind(col_a,col_b,col_c,col_d,col_e)

In df2 all the possible values are present, from 1 to 5, that is the only difference with df, in which only 1,2 and 5 are possible values. Hence I thought this could explain the error, that there are 3 possible values in the data frame while the value.labels contain 5 distinct options. But even when I take out the argument legendLabels from the function (so there is no incongruency between the actual values and all the possible labels) I still get the same error when trying to plot df.

Any hints?

1

There are 1 answers

0
Daniel On BEST ANSWER

The function needs to know the amount of item categories to work. Usually, this is done automatically by examining the data.frame.

If this does not work for you, try the catcount parameter:

catcount = 4

should work. I have improved catcount detection in the current developer build (see Github), which also warns the user, if this parameter is required.