Closed seandalby closed 1 year ago
Thanks, that is something to look into why it goes wrong:
> pa_acs_tr_space <- pa_acs_tr %>% group_by(county) %>%
summarise(med_inc = mean(med_hh_inc, na.rm = TRUE))
Error:
! Assigned data `geom` must be compatible with existing data.
✖ Existing data has 67 rows.
✖ Assigned data has 119 rows.
ℹ Only vectors of size 1 are recycled.
Run `rlang::last_error()` to see where the error occurred.
alternative to summarise
you can use
aggregate(pa_acs_tr["med_hh_inc"], list(county = pa_acs_tr$county), mean, na.rm = TRUE)
Setting sf_use_s2(FALSE)
solves your issue with summarise()
. #1771
Amazing, thanks so much @edzer
Hi - my code below requires the "tidycensus" package (and a us census api key) to load the data but should be reproducible after that with sf etc. -
I'm looking at income across years from ACS 5-year estimates and pull in the data as follows:
From here, the code below works:
But this code doesn't:
I can work around this by grouping just on the data.frame and then joining to a county-level sf object later. I'm thinking I might be asking group_by / summarise to do too much, but is there a good reason why it won't "aggregate" across years when the same geometry is being used?
Thanks!