anycensus: Query Korean census data by admin code (province or...

View source: R/anycensus.R

anycensusR Documentation

Query Korean census data by admin code (province or municipality) and year

Description

The function queries a long format census data frame (censuskor) for specific administrative codes (if provided)

Usage

anycensus(
  year = 2020,
  codes = NULL,
  type = c("population", "housing", "tax", "mortality", "economy", "medicine",
    "migration", "environment", "welfare", "social security", "landuse"),
  level = c("adm2", "adm1"),
  aggregator = sum,
  geometry = FALSE,
  ...
)

Arguments

year

integer(1). One of 2010, 2015, or 2020.

codes

integer vector of admin codes (e.g. c(11, 26)) or character administrative area names (e.g. c("Seoul", "Daejeon")).

type

character(1). "population", "housing", "tax", "economy", "medicine", "migration", "environment", "mortality", "social security", or "landuse". Defaults to "population".

level

character(1). "adm1" for province-level or "adm2" for municipal-level. Defaults to "adm2".

aggregator

function to aggregate values when level = "adm1".

geometry

logical(1). If TRUE, returns an sf object with geometries attached. Defaults to FALSE.

...

additional arguments passed to the aggregator function. (e.g., na.rm = TRUE).

Value

A data.frame object containing census data for the specified codes and year.

Note

Using characters in codes has a side effect of returning all rows in the dataset that match year and type. The 'wide' table is returned with separate columns for each class1 and class2 and unit (abbreviated whereof) combination.

Examples

# Query mortality data for adm2_code 21 (Busan)
anycensus(codes = 21, type = "mortality")

# Query population data for adm1 "Seoul" or "Daejeon"
anycensus(codes = c("Seoul", "Daejeon"), type = "housing", year = 2015)

# Aggregate to adm1 level tax (province-level) using sum
anycensus(
  codes = c(11, 23, 31),
  type = "tax",
  year = 2020,
  level = "adm1",
  aggregator = sum,
  na.rm = TRUE
)

tidycensuskr documentation built on May 4, 2026, 9:09 a.m.