Skip to contents

[Experimental]

Joins regions in data that has already been aggregated to a common geography, for example to correct for likely geocoding anomalies as determined by `tongfen_anomaly_joins`. The data, and the geometries if the data is of class sf, of the regions that get joined are aggregated, all other regions are left as they are.

Variables are aggregated according to the metadata, numeric variables that are not part of the metadata are assumed to be additive. Variables that are not additive, like averages, can only be aggregated if their parent variable is part of the data. If that is not the case use `tongfen_join_correspondence` to update the correspondence the data was built from and aggregate the original data again with `tongfen_aggregate`.

Usage

tongfen_join_regions(data, joins, meta = NULL, id = "TongfenID", na.rm = TRUE)

Arguments

data

data on a common geography, with one row per region, for example as returned by `tongfen_aggregate` or `get_tongfen_ca_census`

joins

table with the regions to join as returned by `tongfen_anomaly_joins`, with the identifier of the region and the identifier of the joined region it becomes part of in the column named like the identifier with suffix `_joined`

meta

optional metadata containing aggregation rules as for example returned by `meta_for_ca_census_vectors`, variables are matched by their label. Numeric variables that are not part of the metadata are treated as additive, if `NULL` (the default) that is the case for all numeric variables

id

name of the column that uniquely identifies the regions, default is "TongfenID"

na.rm

logical, determines how NA values should be treated when aggregating variables, default is `TRUE`

Value

The data with the regions joined. Joined regions take the place and the identifier of the region with the smallest identifier among the regions they are made up of. Variables that are not numeric and not part of the metadata are `NA` for joined regions.

Examples

# Correct 2001 through 2021 dissemination area level population timelines in the
# City of Vancouver for likely geocoding problems
if (FALSE) { # \dontrun{
datasets <- c("CA01","CA06","CA11","CA16","CA21")
meta <- meta_for_additive_variables(datasets,"Population")
data <- get_tongfen_ca_census(regions=list(CSD="5915022"),meta=meta,level="DA",base_geo="CA21")

joins <- tongfen_anomaly_joins(data,paste0("Population_",datasets))
corrected_data <- tongfen_join_regions(data,joins,meta)
} # }