Add an equivalent HOOD_158 column to a HOOD_140-keyed data.frame
Source:R/toronto_neighbourhoods.R
morie_tps_add_hood_158_from_140.RdLooks up each row's HOOD_140 (or hood_140 / NEIGHBOURHOOD_140
/ neighbourhood_140) in the bundled crosswalk and writes the
PRIMARY-overlap 158 hood code into a new column (default name
HOOD_158_equiv).
Usage
morie_tps_add_hood_158_from_140(
df,
col_in = NULL,
col_out = "HOOD_158_equiv",
crosswalk = NULL
)Arguments
- df
A TPS crime
data.frame.- col_in
Name of the input HOOD_140 column. By default the first match from
c("HOOD_140", "hood_140", "NEIGHBOURHOOD_140", "neighbourhood_140")present indf.- col_out
Name of the new column to add. Default
"HOOD_158_equiv".- crosswalk
Optional pre-loaded crosswalk; defaults to
morie_to_hood_crosswalk().
Details
For 1:1 mappings the result is exact. For splits (1 historical hood -> 2–4 current hoods) the 158 hood with the largest area overlap wins; this is lossy – analyses at the 158-level should ideally re-aggregate from the per-incident lat/lon rather than relying on the primary-overlap join.
Examples
df <- data.frame(EVENT_ID = 1:3, HOOD_140 = c("082", "001", "075"))
morie_tps_add_hood_158_from_140(df)
#> EVENT_ID HOOD_140 HOOD_158_equiv
#> 1 1 082 163
#> 2 2 001 001
#> 3 3 075 168