View source: R/age-population.R
age_population | R Documentation |
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.
age_population(
data,
location_col = NULL,
location = NULL,
age_col,
year_col = NULL,
year = NULL
)
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 |
character vector with location names. If using, both
|
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 |
numeric vector representing the desired year(s). If using, both
|
tidy dataset with information on population of different age bands
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
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.