add_back_nbhds: Add Back Missing Neighbourhoods to a Long Tibble

View source: R/get_pts_neighbourhood.R

add_back_nbhdsR Documentation

Add Back Missing Neighbourhoods to a Long Tibble

Description

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.

Usage

add_back_nbhds(data, var, na_to_zero = TRUE)

Arguments

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?

Value

A 111-row tibble

Examples

## 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)

Ottawa-Neighbourhood-Study/onsr documentation built on June 19, 2022, 11:46 a.m.