aggregate.data.frame中的错误:参数必须具有相同的长度 [英] Error in aggregate.data.frame : arguments must have same length

查看:1928
本文介绍了aggregate.data.frame中的错误:参数必须具有相同的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到此错误,但我不太清楚这意味着什么。我所有的变量名都是一致的,没有错字。

I keep getting this error and I'm not quite sure what it means. All of my variable names are consistent and there are no typos. Am I missing something here?

代码

datNewagg <- aggregate (dataNew, by = list('x', 'y', 'z', 'a', 'ab'), 
                                                             FUN = mean)  

产生错误

  Error in aggregate.data.frame(datNew, by = list("x", "y",  : 
  arguments must have same length


推荐答案

假定它不是拼写错误(数据帧在呼叫中称为 dataNew ,但错误中的datNew )分别是 x y z a ab dataNew中的列名

Assuming it's not a typo (the data frame is called dataNew in your call but datNew in the error), are x, y, z, a and ab the names of columns in dataNew?

某些功能,例如 子集 ,将允许您指定其直接处理的对象的列名。 聚合 函数没有,因此 dataNew by 自变量中列出的>需要特别提及。试试这个:

Some functions, like subset, will allow you to specify column names of the object they're working on directly. The aggregate function doesn't, so any columns of dataNew listed in the by argument need to specifically referred to as such. Try this:

datNewagg <- aggregate(dataNew,
    by = list(
        x = dataNew$x,
        y = dataNew$y,
        z = dataNew$z,
        a = dataNew$a,
        ab = dataNew$ab),
    FUN = mean) 

这篇关于aggregate.data.frame中的错误:参数必须具有相同的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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