Get observations of a FRED series
Given a series ID, return observations of that series as a tibble object.
fredr() is an alias for fredr_series_observations().
fredr_series_observations( series_id, ..., observation_start = NULL, observation_end = NULL, frequency = NULL, aggregation_method = NULL, limit = NULL, offset = NULL, sort_order = NULL, units = NULL, realtime_start = NULL, realtime_end = NULL, vintage_dates = NULL, output_type = NULL ) fredr( series_id, ..., observation_start = NULL, observation_end = NULL, frequency = NULL, aggregation_method = NULL, limit = NULL, offset = NULL, sort_order = NULL, units = NULL, realtime_start = NULL, realtime_end = NULL, vintage_dates = NULL, output_type = NULL )
series_id |
A string ID for the FRED series. |
... |
These dots only exist for future extensions and should be empty. |
observation_start |
A |
observation_end |
A |
frequency |
A string representing a lower frequency to aggregate to. Defaults to no frequency aggregation. Possible values are:
|
aggregation_method |
A string representing the aggregation method
used for frequency aggregation. This parameter has no affect is
|
limit |
An integer limit on the maximum number of results to return.
Defaults to |
offset |
An integer used in conjunction with |
sort_order |
A string representing the order of the resulting series.
Possible values are: |
units |
A string indicating the data value transformation.
Defaults to
|
realtime_start |
A |
realtime_end |
A |
vintage_dates |
A vector of |
output_type |
An integer indicating the output type. Not used unless
|
A tibble object with observation dates and values.
if (fredr_has_key()) {
# Observations for "UNRATE" series between 1980 and 2000. Units are in terms
# of change from previous observation.
fredr(
series_id = "UNRATE",
observation_start = as.Date("1980-01-01"),
observation_end = as.Date("2000-01-01"),
units = "chg"
)
# All observations for "OILPRICE" series. The data is first aggregated by
# quarter by taking the average of all observations in the quarter then
# transformed by taking the natural logarithm.
fredr(
series_id = "OILPRICE",
frequency = "q",
aggregation_method = "avg",
units = "log"
)
# To retrieve values for multiple series, use purrr's map_dfr() function.
if (requireNamespace("purrr", quietly = TRUE)) {
library(purrr)
purrr::map_dfr(c("UNRATE", "OILPRICE"), fredr)
# Using purrr::pmap_dfr() allows you to use varying optional parameters
params <- list(
series_id = c("UNRATE", "OILPRICE"),
frequency = c("m", "q")
)
purrr::pmap_dfr(
.l = params,
.f = ~ fredr(series_id = .x, frequency = .y)
)
}
}Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.