age_population: Get cleaned population data with lower and upper limits of...

View source: R/age-population.R

age_populationR Documentation

Get cleaned population data with lower and upper limits of age.

Description

This function helps clean up datasets of population data, which might be similar to socialmixr::wpp_age() or a dataset with columns representing: population, location, age, and year. If age is numeric, it groups ages into age groups with 5 year bins (0-4, 5-9, etc). It then separates age groups into two column of these lower and upper limits. Finally, it filters data passed to the specified year and location. If no year or location is provided then all years or locations are used.

Usage

age_population(
  data,
  location_col = NULL,
  location = NULL,
  age_col,
  year_col = NULL,
  year = NULL
)

Arguments

data

dataset containing information on population for a given age, country, and year

location_col

bare variable name for the column with location information. If using, both location_col & location must be specified.

location

character vector with location names. If using, both location_col & location must be specified.

age_col

bare variable name for the column with age information

year_col

bare variable name for the column with year information. If using, both year_col & year must be specified.

year

numeric vector representing the desired year(s). If using, both year_col & year must be specified.

Value

tidy dataset with information on population of different age bands

Examples

world_data <- socialmixr::wpp_age()
world_data
# Tidy data for multiple locations across different years
age_population(
  data = world_data,
  location_col = country,
  location = c("Asia", "Afghanistan"),
  age_col = lower.age.limit,
  year_col = year,
  year = c(2010:2020)
)

# Tidy data for a given location irrespective of year
age_population(
  data = world_data,
  location_col = country,
  location = "Afghanistan",
  age_col = lower.age.limit
)

# Tidy data for a given location irrespective of location
age_population(
  data = world_data,
  age_col = lower.age.limit
)
age_population(
  data = world_data,
  age_col = lower.age.limit,
  year_col = year,
  year = c(2011:2015)
)

# Tidy datasets with age groups
population_age_groups <- abs_pop_age_lga_2020
population_age_groups
age_population(
  data = population_age_groups,
  age_col = age_group,
  year_col = year,
  year = 2020
)

# Tidy datasets with numeric age
population_numeric_age <- abs_age_state("WA")
population_numeric_age
age_population(
  data = population_numeric_age,
  age_col = lower.age.limit,
  year_col = year,
  year = 2020
)


njtierney/conmat documentation built on April 17, 2025, 10:27 p.m.