首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误“参数意味着不同的行数: x,y”意味着什么?

错误“参数意味着不同的行数: x,y”意味着什么?
EN

Stack Overflow用户
提问于 2019-11-18 18:19:12
回答 1查看 1.2K关注 0票数 0

我有一个包含43958行和3列(问题、项目和值)的data.frame,我试图运行一个统计测试,但是我正在处理这个错误:

Data.frame中的错误(problem.name= problem.name,avg.imp = avg.imp,k.esd = k.esd):参数意味着不同的行数: 1,0

我的剧本是:

代码语言:javascript
复制
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

有人能告诉我怎么解决这个错误吗?

这是一个数据示例:

代码语言:javascript
复制
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

问题

EN

回答 1

Stack Overflow用户

发布于 2019-11-18 18:44:02

当您将数据帧分配给row时,似乎没有填充其中一个变量。

当您尝试从不同长度的向量创建数据帧时,会发生这样的情况,例如,其中一个向量是空的:

代码语言:javascript
复制
row <- data.frame(problem.name="X",
                  avg.imp= 5,
                  k.esd=vector())

这将给出以下错误:

Data.frame中的错误(problem.name= "X",avg.imp = 5,k.esd =vector():参数意味着不同的行数: 1,0

仔细检查你的代码。我怀疑问题就发生在这里:

代码语言:javascript
复制
problem.name <- variables[problem]

但我无法检查这一点,因为没有提供数据示例。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58920665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档