Skip to contents

[Maturing]

Aggregate variables specified in meta for several datasets according to correspondence.

Usage

tongfen_aggregate(
  data,
  correspondence,
  meta = NULL,
  base_geo = NULL,
  na.rm = TRUE
)

Arguments

data

named list of datasets to be aggregated. The names identify the datasets, they are matched against the `geo_dataset` column in `meta` to pick the aggregation rules and labels for each dataset. Without names, or with names not found in `meta`, the rules for all datasets are applied and the variables keep their original names

correspondence

correspondence data for gluing up the datasets

meta

metadata containing aggregation rules as for example returned by `meta_for_ca_census_vectors`

base_geo

identifier for which data element to base the final geography on, uses the first data element if `NULL` (default), expects that `base_geo` is an element of `names(data)`.

na.rm

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

Value

aggregated dataset of class sf if base_geo is not NULL and data is of type sf or tibble otherwise.

Examples

# aggregate census tract level 2006 and 2016 population data on common geography built through
# correspondence from 2006 and 2016 census tracts in the City of Vancouver.
if (FALSE) { # \dontrun{
regions <- list(CSD="5915022")
geo1 <- cancensus::get_census("CA06",regions=regions,geo_format='sf',level='CT')
geo2 <- cancensus::get_census("CA16",regions=regions,geo_format='sf',level='CT')
meta <- meta_for_additive_variables(c("CA06","CA16"),"Population")
correspondence <- get_tongfen_correspondence_ca_census(geo_datasets=c('CA06','CA16'),
                                                       regions=regions,level='CT')
result <- tongfen_aggregate(list(CA06=geo1 %>% rename(GeoUIDCA06=GeoUID),
                                 CA16=geo2 %>% rename(GeoUIDCA16=GeoUID)),correspondence,meta)
} # }