Guilherme Freitas
Guilherme Freitas

Reputation: 9

What does the error “arguments imply differing number of rows: x, y” mean?

I have a data.frame with 43958 rows and 3 columns (problem, project and value), and I'm trying to run an statistical test, but I'm dealing in this error:

Error in data.frame(problem.name = problem.name, avg.imp = avg.imp, k.esd = k.esd) : arguments imply differing number of rows: 1, 0

My script bellow:

require('ScottKnottESD')
require('rowr')


sk_format <- function (data){
   variables <- unique(data$problem)
   result <- data.frame(matrix(ncol=length(variables),nrow=113))
   for(i in seq(1,length(variables))){
      result[i] <- data$value[data$problem==variables[i]]
   }
 colnames(result) <- variables
 return (result)
}

avg.imp  <- function(data){
   data.esd <- sk_esd(sk_format(data))
   data.esd <- data.frame(data.esd$groups)
   data.esd$problem <- rownames(data.esd)
   rownames(data.esd) <- NULL

   result <- data.frame(problem.name=vector(),
             avg.imp=vector(),
             k.esd=vector())

   variables <- unique(data$problem)
   print(length(variables))
   for(problem in 1:length(variables)){
      sub <- data[data$problem==variables[problem],]

   avg.imp <- mean(sub$value)
   problem.name <- variables[problem]
   k.esd <- data.esd[data.esd$problem==paste(problem.name),1]

   row <- data.frame(problem.name=problem.name,
   avg.imp=avg.imp,
   k.esd=k.esd)

   result <- rbind(result, row)
 }
   return (result)
}

eclipse.varimp <- read.csv("agora_vai.csv", sep = ",")

eclipse.vimp <- avg.imp(eclipse.varimp)
eclipse.vimp

Anyone can tell me how I can solve this error?

This is a data sample:

project,problem,value
albertoirurueta_irurueta-navigation,squid:CommentedOutCodeLine,0
albertoirurueta_irurueta-navigation,squid:S2129,0
albertoirurueta_irurueta-navigation,javascript:S1126,0
albertoirurueta_irurueta-navigation,Web:PageWithoutTitleCheck,0
albertoirurueta_irurueta-navigation,squid:S1155,0
albertoirurueta_irurueta-navigation,squid:S4784,0

problem

Upvotes: 0

Views: 1208

Answers (1)

slava-kohut
slava-kohut

Reputation: 4233

Looks like one of the variables is not populated when you assign a data frame to row.

This is what happens when you try to create a data frame from vectors of different lengths, for example, one of them being empty:

row <- data.frame(problem.name="X",
                  avg.imp= 5,
                  k.esd=vector())

This gives you the following error:

Error in data.frame(problem.name = "X", avg.imp = 5, k.esd = vector()) : arguments imply differing number of rows: 1, 0

Check your code carefully. I suspect that the problem happens here:

problem.name <- variables[problem]

But I cannot check this because there is no data sample provided.

Upvotes: 1

Related Questions