get_idb_data {RcensusPkg} | R Documentation |
get_idb_data
Description
Get data from the Census Bureau's Time Series International Database for a specific dataset: Single Year of Age and Sex("1year") or 5-Year Age Groups and Sex("5year"), year, variables, and country. See Census Bureau's publicly available International Database for dataset descriptions.
Usage
get_idb_data(
dataset = NULL,
years = 2023,
vars = NULL,
group = FALSE,
wide_to_long = FALSE,
countries = NULL,
ages = 1:100,
sex = c(0, 1, 2),
key = Sys.getenv("CENSUS_KEY")
)
Arguments
dataset |
A required string that selects the dataset of interest. Acceptable values are "1year" or "5year". |
years |
An optional numeric vector that sets the years of interest. The default is 2023. |
vars |
An optional string vector of variable names to be acquired. The default is GEO_ID,NAME,GENC,POP for either "1year" or "5year". |
group |
A logical that if |
wide_to_long |
The returned |
countries |
An optional string vector of country/area abbreviations (GENC Standard Countries and Areas) of interest. GENC codes are available here. |
ages |
An optional numeric that selects specific ages(0 to 100 range) from the 1year dataset. Default is all ages. |
sex |
An optional numeric vector to select the sex of interest from the 1year dataset. Acceptable values 0 - Both, 1 - Male, 2 - Female. Default is all three values for sex. |
key |
A string that sets the access key. All Census Bureau API requests require an access key.
Sign-up for a key is free and can be obtained here.
The function will check for a global setting of the key via |
Details
For the "1year", a data.table
is returned with the following columns:
GEO_ID | char - geo id string |
NAME | char - name of the country |
GENC | char - GENC country abbreviation |
POP | char - the total population for a specific age and sex in the country |
YR | char - the year of the estimate |
AGE | char - the specific age are values from 1 to 100 |
SEX | char - the specific sex with values 0 - Both, 1 - Male, 2 - Female |
More details are available here.
For the "5year", see 5year and the 119 variable names and descriptions.
Value
A data.table
Examples
## Not run:
# Requires Census Bureau API key
library(data.table)
library(httr2)
library(jsonlite)
library(RcensusPkg)
# 1year wide form, default variables, 2 countries
# (Botswana, Norway)
one_year_dt <- RcensusPkg::get_idb_data(
dataset = "1year",
years = c(2023, 2024),
countries = c("BW", "NO")
)
# 5year long form, all variables, 2023, country = US
five_year_US_long_group_dt <- RcensusPkg::get_idb_data(
dataset = "5year",
years = 2023,
group = TRUE,
countries = "US",
wide_to_long = TRUE
)
## End(Not run)