-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aggregate.sf does not return an object with the same length as by #452
Comments
I think it works as documented. |
Thanks for the response and sorry for the slow reply. Just taken a look over the latest version of the documentation and it seems that the behaviour when the aggregating object ( Given many sf useRs will be coming from sp (as acknowledged in the very useful work going into #210 ) it's likely that they will assume the same behaviour in equivalent sf functions, especially for commonly used and generic methods like My view is that |
I've merged your #451 PR. I looked at d = data.frame(a = 1:4, b = factor(c("a", "a", "b", "b"), levels = c("a", "b", "c")))
> aggregate(d[1], list(b = d$b), mean)
b a
1 a 1.5
2 b 3.5 and noted that it doesn't give output ( |
Here's another reprex showing behaviour under my PR version: devtools::install_github("robinlovelace/sfr", ref = "aggregate")
#> Skipping install of 'sf' from a github remote, the SHA1 (ce84f94d) has not changed since last install.
#> Use `force = TRUE` to force installation
library(sp)
# from ?aggregate.Spatial
data("meuse")
coordinates(meuse) <- ~x + y
data("meuse.grid")
coordinates(meuse.grid) <- ~x + y
gridded(meuse.grid) <- TRUE
meuse.grid$part.a[1:3] = 2
abc = rgeos::gUnaryUnion(as(meuse.grid, "SpatialPolygons"), meuse.grid$part.a)
x = aggregate(meuse[c("zinc", "copper")], abc, mean)
nrow(x) # 3 features outputed
#> [1] 3
# with sf
library(sf)
#> Linking to GEOS 3.5.1, GDAL 2.2.1, proj.4 4.9.2, lwgeom 2.3.3 r15473
meuse_sf = st_as_sf(meuse)
abc_sf = st_as_sf(abc)
x_sf = aggregate(meuse_sf[c("zinc", "copper")], abc_sf, mean)
nrow(x_sf)
#> [1] 3 |
Useful to have an example showing non-spatial behaviour. I think that example is rather specific to factor data. Another example that I think supports keeping the geometry of d = data.frame(a = c(1:3, NA), b = c("a", "a", "b", "c"))
aggregate(d[1], list(b = d$b), mean)
#> b a
#> 1 a 1.5
#> 2 b 3.0
#> 3 c NA |
Reproducible example:
The text was updated successfully, but these errors were encountered: