我有一个包含43958行和3列(问题、项目和值)的data.frame,我试图运行一个统计测试,但是我正在处理这个错误:
Data.frame中的错误(problem.name= problem.name,avg.imp = avg.imp,k.esd = k.esd):参数意味着不同的行数: 1,0
我的剧本是:
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有人能告诉我怎么解决这个错误吗?
这是一个数据示例:
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发布于 2019-11-18 18:44:02
当您将数据帧分配给row时,似乎没有填充其中一个变量。
当您尝试从不同长度的向量创建数据帧时,会发生这样的情况,例如,其中一个向量是空的:
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
仔细检查你的代码。我怀疑问题就发生在这里:
problem.name <- variables[problem]但我无法检查这一点,因为没有提供数据示例。
https://stackoverflow.com/questions/58920665
复制相似问题