View source: R/get_pts_neighbourhood.R
add_back_nbhds | R Documentation |
This function takes a long tibble with a column for ONS IDs and
a column for count data and adds rows for any missing ONS IDs. This is
useful after you do a spatial join, e.g. using onsr::get_pts_neighbourhood()
,
and then do a count with dplyr::summarise()
, since any neighbourhoods not
represented in the input data won't get a row in the output.
add_back_nbhds(data, var, na_to_zero = TRUE)
data |
A tibble containing counts of points in neighbourhoods, with fewer than 111 rows. In other words, some neighbourhoods are missing. |
var |
The column containing the count data. |
na_to_zero |
Boolean: Should NA values be converted to 0? |
A 111-row tibble
## Not run: # example using fictitious data ons_shp <- onsr::get_ons_shp() neighbourhood_counts <- onsr::get_pts_neighbourhood(pts = point_data, pgon = ons_shp) %>% sf::st_set_geometry(NULL) %>% dplyr::group_by(ONS_ID) %>% dplyr::summarise(num = n()) %>% onsr::add_back_nbhds(var = "num") ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.