I think you might need to rewrite the FUN bit like this: (example from the aggregate help file):
library(datasets)
aggregate(state.x77, list(Region = state.region), function(x) round(mean(x, na.rm = TRUE), 2))
#> Region Population Income Illiteracy Life Exp Murder HS Grad Frost
#> 1 Northeast 5495.11 4570.22 1.00 71.26 4.72 53.97 132.78
#> 2 South 4208.12 4011.94 1.74 69.71 10.58 44.34 64.62
#> 3 North Central 4803.00 4611.08 0.70 71.77 5.28 54.52 138.83
#> 4 West 2915.31 4702.62 1.02 71.23 7.22 62.00 102.15
#> Area
#> 1 18141.00
#> 2 54605.12
#> 3 62652.00
#> 4 134463.00
Created on 2020-09-28 by the reprex package (v0.3.0)