data_for_table: Prepare Population Data for Tabular Display
Description
Prepares population data for tabular display (e.g., in reports or Shiny apps).
The function reshapes the data by sex, adds total population, and computes the
sex ratio, while also attaching province names and labels.
Usage
data_for_table(data, reg_code, harmonized = TRUE)
Value
A data frame in wide format with columns:
province_id — province identifier
province — province name
year — census year
age5 — five-year age group label
Male — male population
Female — female population
Male+Female — total population
sex_ratio — ratio of males to females (per 100 females)
Arguments
data
A data frame containing population data for a specific province
and year. Must include columns: year, province_id, sex, age5, and pop.
reg_code
Integer or character. Province code used to retrieve
the province name.
harmonized
Logical. If TRUE (default), province codes are treated as
harmonized; if FALSE, non-harmonized codes are used.
Details
The function performs the following steps:
Adds the province name using reg_name().
Relabels sex and age5 using reference tables in ref_label.
Reshapes data into wide format with separate columns for Male and Female.