length fails in aggregate function

This is from some R code that worked at one time, and I can't figure what changed.

I want to use the aggregate() function to find the mean, sd, and length of the columns in the PlantGrowth data table.

library("datasets")
data("PlantGrowth")
aggregate(weight ~ group, data = PlantGrowth, mean)
aggregate(weight ~ group, data = PlantGrowth, sd)
aggregate(weight ~ group, data = PlantGrowth, length)

The first two work, producing the mean and standard deviation. The last one doesn't, giving me the error

Error in get(as.character(FUN), mode = "function", envir = envir) : 
  object 'FUN' of mode 'function' was not found

As far as I know, you can find the lengths (which is the number of observations, 10) using this method...or at least can't figure out why you can't.

Glad to know it works, although still not on my system. I have not used length in any way in other places of my script, although I’ve done a day’s worth of computing in this R session.

Maybe try calling the length function directly with ::

aggregate(weight ~ group, data = PlantGrowth, base::length)
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.