Learn R Programming

tidycensuskr (version 0.2.5)

anycensus: 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"),
  level = c("adm2", "adm1"),
  aggregator = sum,
  geometry = FALSE,
  ...
)

Value

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

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", or "social security". 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).

Examples

Run this code
# 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
)

Run the code above in your browser using DataLab