am_data {africamonitor} | R Documentation |
Retrieve Data from the Database
Description
This is the main function of the package to retrieve data from the database.
Usage
am_data(
ctry = africamonitor::am_countries$ISO3,
series = NULL,
from = NULL,
to = NULL,
labels = TRUE,
wide = TRUE,
expand.date = FALSE,
drop.1iso3c = TRUE,
ordered = TRUE,
return.query = FALSE,
...
)
Arguments
ctry |
character. (Optional) the ISO3 code of countries (see |
series |
character. (Optional) codes of series matching the 'Series' column of the series table (retrieved using |
from |
set the start time of the data retrieved by either supplying a start date, a date-string of the form |
to |
same as |
labels |
logical. |
wide |
logical. |
expand.date |
logical. |
drop.1iso3c |
logical. If only one country is selected through |
ordered |
logical. |
return.query |
logical. |
... |
further arguments passed to |
Details
If labels = FALSE
, the series table is not joined to the data table, and ordered = TRUE
will order series retrieved in alphabetic order.
If labels = TRUE
data is ordered by series and date, preserving the order of columns in the dataset. If multiple countries are received they are ordered alphabetically according to the 'ISO3' column.
Series at different frequencies can be queried, but, if wide = TRUE
, this will result in missing values for all but the first observations per period in the lower frequency series.
Value
A data.table
with the result of the query.
See Also
am_pivot_wider
, am_expand_date
, africamonitor
Examples
# Return all indicators for Kenya from 2000
am_data("KEN", from = 2000)
# Return all indicators for Kenya from 2000 in long format
am_data("KEN", from = 2000, wide = FALSE)
# Return with date expanded
am_data("KEN", from = 2000, expand.date = TRUE)
# Same thing in multiple steps (with additional customization options):
am_data("KEN", from = 2000, wide = FALSE) |> am_pivot_wider() |> am_expand_date()
# Getting only GDP growth
am_data("KEN", "NGDP_RPCH", from = 2000)
# Getting GDP growth for all countries
am_data(series = "NGDP_RPCH", from = 2000)
# Reshaping to wider format
am_data(series = "NGDP_RPCH", from = 2000) |>
am_pivot_wider(id_cols = "Date",
names_from = "ISO3",
values_from = "NGDP_RPCH")
# Getting growth and inflation for the EAC countries (all available years)
am_data(ctry = c("UGA", "KEN", "TZA", "RWA", "BDI", "SSD"),
series = c("NGDP_RPCH", "PCPIPCH"))