R/track-merge.R

Defines functions track_merge

Documented in track_merge

#' Get geo code that are merged after code change
#'
#' @inheritParams get_code
#' @return Dataset of class `data.table` with column `merge` showing the number
#'   of time the codes have been merged into
#' @examples
#'  dt <- track_merge("kommune", 2018, 2020)
#' @export

track_merge <- function(type = c(
  "fylke",
  "kommune",
  "bydel",
  "grunnkrets"
),
from = NULL,
to = NULL,
names = TRUE) {
  type <- match.arg(type)
  dt <- track_change(type, from, to)
  data.table::setkey(dt, currentCode, changeOccurred)
  dt[!is.na(currentCode), merge := .N, by = data.table::rleid(changeOccurred, currentCode)]
  out <- dt[merge > 1]

  if (!names)
    out[, (granularityNames) := NULL]

  return(out)
}

Try the norgeo package in your browser

Any scripts or data that you put into this service are public.

norgeo documentation built on Aug. 15, 2023, 5:06 p.m.