R中的错误消息:没有要聚合的行 [英] error message in r: no rows to aggregate

查看:884
本文介绍了R中的错误消息:没有要聚合的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个用r语言编写的程序,该程序旨在将许多csv数据文件编译成一个csv文件,然后生成一个输出文件,其中包含对组合文件中选择的几个变量进行简单计算的输出。通过使用组合文件作为输入,选择变量并指定我需要的值的类型,可以完成后面的过程。除此以外,还每天获取数据文件,然后通过r程序获取数据分析,例如在选定时间间隔内对数据的最小值,最大值,平均值或总和进行分析。

I am running a program written in r language which is designed to compile many csv data files into one csv file and then generate an output file that contains the output of simple calculations on the few variables selected in the combined file. The later process is done by using the combined file as an input, selecting variables and specifying the kind of values that I need. Adding onto this explanation, data files are obtained on daily basis and these go through the r program to obtain some analysis, such as min, max, mean or sum of the data in selected time intervals.

继续讨论该程序存在的问题,该程序通常能够生成合并的csv文件,但没有太大问题,但是涉及到产生输出文件时,程序有时会生成聚合错误消息:

Moving on to the problem that I have with this program, the program is usually able to generate the combined csv file without much problem, but when it comes to the part of producing an output file, the program sometimes generate the aggregation error message:

aggregate.date.frame中的错误(mf [1L],mf [-1L] ,FUN = FUN,...):
没有要聚合的行

此错误消息仅在某些组合数据文件中出现,并且是使我更加困惑的是,导致此类问题的合并的csv文件中的数据与不会导致此问题的合并的文件没有显示任何差异。但是,目前我仍然怀疑合并的数据csv文件而不是程序应该有问题,因为该程序通常可以在许多分析情况下正常工作。

This error message only appears for some combined data files, and is making me even more puzzled since the data in the combined csv files that are causing such problem do not show any difference with the combined files that do not cause this problem. However, currently I am still suspecting that there should be something wrong with the combined data csv files instead of the program since the program generally works fine for many analysis cases.

,该程序正在使用聚合函数来计算输出文件。

Basically, the program is using aggregate function to compute the output file.

我对使用r很陌生,而我正在使用的程序由几个阶段组成,所以我抱歉,如果我的解释不清楚。

I am quite new to using r, and the program that I am using consists of several stages, so I apologize if my explanation was rather unclear.

至少,我想知道这种聚合错误的可能原因是什么。

At least, I would like to know what are the possible causes for such aggregation error. Thank you in advance.

推荐答案

之所以出现此错误,是因为传递给聚合的对象(无论与<$ c匹配的对象) $ c> x )的行为零。

This error is given because the object that is passed to aggregate (whatever is matched to x) has zero rows.

以下给出了函数的前10行:

The following gives the first 10 rows of the function:

> head(aggregate.data.frame, 10)

1  function (x, by, FUN, ..., simplify = TRUE)                               
2  {                                                                         
3      if (!is.data.frame(x))                                                
4          x <- as.data.frame(x)                                             
5      FUN <- match.fun(FUN)                                                 
6      if (NROW(x) == 0L)                                                    
7          stop("no rows to aggregate")                                      
8      if (NCOL(x) == 0L) {                                                  
9          x <- data.frame(x = rep(1, NROW(x)))                              
10         return(aggregate.data.frame(x, by, function(x) 0L)[seq_along(by)])

因此,在调用汇总之前,请调用 NROW 在对象上,它将我告诉你是否为零可能由于某些原因而发生这种情况,但是由于没有可复制的示例,因此很难知道。原因之一可能是 x 与错误的参数匹配。但是,如果某些csv文件运行良好,则可能并非如此。该对象确实确实有0行,可能是由于子集。

so before you call aggregate, call NROW on the object and it will tell you if it's zero. This could happen because of a few reasons, but without a reproducible example it's hard to know. One reason might be that x is getting matched to the wrong argument. But if it's working well for some of the csv files then that is probably not the case. It's more likely that the object really does have 0 rows, perhaps because of subsetting.

这篇关于R中的错误消息:没有要聚合的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆