Count number of mutations in a given time period
Usage
mutation_count(
mutations,
start_date,
end_date = Sys.Date(),
territorial_changes_only = FALSE
)Arguments
- mutations
A tibble containing the municipality mutations inventory (see
import_CH_municipality_inventory)- start_date
Date vector (incl)
- end_date
Date vector (excluded)
- territorial_changes_only
boolean. FALSE if all mutations should be considered. TRUE if mutations that have an effect on the municipal territory only should be considered. FALSE includes name changes, Bezirk number changes etc.
Value
A list with 4 elements:
mapped: A tibble with the mapped municipalities
unmapped: A tibble with the unmapped municipalities
state_old: see above
state_new: see above
Details
Approach
Download the Swiss municipality inventory
Import it into R workspace with
import_CH_municipality_inventorySet the old state and the new state (see example)
Get the mapping table with this function
Example Daettwil / Baden
On 1.1.1962 Daettwil (Bfs Nr. 4025) merged with Baden (Bfs Nr. 4021). Let's define
old_state <- as.Date("1961-01-01")
new_state <- as.Date("1963-01-01")
Result:
bfs_nr_new name_new bfs_nr_old name_old 4021 Baden 4021 Baden 4021 Baden 4025 Daettwil
Examples
mutations <- structure(list(hist_id = c(11227L, 11240L, 13189L),
district_hist_id = c(10025L, 10025L, 10025L),
kanton_abbr = c("AG", "AG", "AG"),
bfs_nr = c(4025L, 4021L, 4021L),
name = c("Daettwil", "Baden", "Baden"),
admission_nr = c(1000L, 1000L, 1004L),
admission_mode = c(20L, 20L, 26L),
admission_date = structure(c(-3653, -3653, -2922),
class = c("Date")),
abolition_nr = c(1004L, 1004L, NA),
abolition_mode = c(29L, 26L, NA),
abolition_date = structure(c(-2923, -2923, NA),
class = c("Date")),
change_date = structure(c(-2923, -2923, -2922), class = c("Date"))),
row.names = c(NA, -3L), class = c("tbl_df", "tbl", "data.frame"))
mapping_object <- map_old_to_new_state(mutations,
as.Date("1961-01-01"), as.Date("1963-01-01"))