Filters the input dataset to return the Nth release (or vintage) of data for each time period. The function supports selecting the first, latest, or a specific numbered release.
Arguments
- df
A data frame containing data vintages. The data frame must include the columns:
pub_date
(publication date of the release)time
(thecorresponding time period for the data).
- n
The release number to extract. Accepts:
Positive integer or vector (e.g., 1 for first release, 2 for second, etc.)
"first"
to extract the first release."latest"
to extract the most recent release. Default is 1 (the first release).
- diagonal
Logical. If
TRUE
, the function only returns real first releases.
Value
A filtered data frame containing only the specified release(s).
The resulting data frame is assigned the class tbl_release
to indicate
its structure. If diagonal is set to TRUE
, the function only returns the
real first releases. That is historic values for which no vintages exist
are not returned.
Details
The behavior depends on the value of n
:
Non-negative integer: The function retrieves the Nth release for each time period (e.g., 0 = first release, 1 = second release, etc.).
"first": Retrieves the first release for each time period (via
get_first_release
)."latest": Retrieves the most recent release for each time period (via
get_latest_release
).
Examples
# Example data
df <- dplyr::filter(reviser::gdp, id=="US")
# Get the first release (n = 0)
first_release <- get_nth_release(df, n = 0)
# Get the latest release
latest_release <- get_nth_release(df, n = "latest")
# Get the second release (n = 1)
second_release <- get_nth_release(df, n = 1)
# Get the first and second release (n = 0:1)
releases <- get_nth_release(df, n = 0:1)