Solution:
Few functions, like subset
, will approve you to seclude column names of the object they're performing on directly. The aggregate
function doesn't, hence any columns of dataNew
listed in the by
argument require to particularly referred to as such. Attempt this:
datNewagg <- aggregate(dataNew,
by = list(
x = dataNew$x,
y = dataNew$y,
z = dataNew$z,
a = dataNew$a,
ab = dataNew$ab),
FUN = mean)
I used obtain this error.
The easy solution to remove this error is to write all the variables along with their dataset name like "ds_name$var_name".
I'm not certain what is the dataset name is your case, so I'll give you another same example.
curYearRev <-aggregate(hr$Year.Total, by = list(hr$Hospital_ID,hr$District_ID,hr$Instrument_ID) , FUN = sum)
Here, "hr" is the dataset name and "Year.Total", "Hospital_ID", "District_ID", "Instrument_ID" are the variables in "hr" dataset.
Check class(dataNew)
. In case it's not a data.frame, this dataNew <- data.frame(dataNew)
prior aggregation must solve the error or
datNewagg <- aggregate (data.frame(dataNew), by = list('x', 'y', 'z', 'a', 'ab'),
You can inspect in case aggregate
method is supported by methods()
.
# stars 0.2-0
> library(stars)
> methods(class= "stars")
[1] [ [<- adrop aperm as.data.frame c coerce
[8] cut dim dimnames dimnames<- filter image initialize
[15] is.na Math merge Ops plot print show
[22] slotsFromS3 split st_apply st_as_sf st_as_sfc st_as_stars st_bbox
[29] st_coordinates st_crop st_crs st_crs<- st_dimensions st_transform st_write
Ta-da! stars 0.3-0
is on CRAN today (25/FEB/2019).
# stars 0.3-0
> library(stars)
> methods(class= "stars")
[1] $<- [ [<- adrop aggregate aperm
[7] as.data.frame c coerce cut dim dimnames
[13] dimnames<- image initialize is.na Math merge
[19] Ops plot print show slotsFromS3 split
[25] st_apply st_area st_as_sf st_as_sfc st_as_stars st_bbox
[31] st_coordinates st_crop st_crs st_crs<- st_dimensions st_geometry
[37] st_redimension st_transform write_stars
You can view aggreagte
is listed.
By the way, in case you include tidyverse
, the list expands like:
> library(tidyverse)
> library(stars)
> methods(class= "stars")
[1] $<- [ [<- adrop aggregate aperm
[7] as.data.frame as.tbl_cube c coerce cut dim
[13] dimnames dimnames<- filter image initialize is.na
[19] Math merge mutate Ops plot print
[25] pull select show slice slotsFromS3 split
[31] st_apply st_area st_as_sf st_as_sfc st_as_stars st_bbox
[37] st_coordinates st_crop st_crs st_crs<- st_dimensions st_geometry
[43] st_redimension st_transform write_stars