Error in aggregate.data.frame : arguments must have same length

前端 未结 5 1528
我寻月下人不归
我寻月下人不归 2021-02-06 02:09

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?

The code

5条回答
  •  借酒劲吻你
    2021-02-06 02:48

    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?

    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) 
    

提交回复
热议问题