valid_year_month {etl} | R Documentation |
Ensure that years and months are within a certain time span
Description
Ensure that years and months are within a certain time span
Usage
valid_year_month(years, months, begin = "1870-01-01", end = Sys.Date())
Arguments
years |
a numeric vector of years |
months |
a numeric vector of months |
begin |
the earliest valid date, defaults to the UNIX epoch |
end |
the most recent valid date, defaults to today |
Details
Often, a data source will begin
and end
at
known points in time. At the same time, many data sources are divided
into monthly archives. Given a set of years
and months
,
any combination of which should be considered valid, this function will
return a data.frame
in which each row is one of those
valid year-month pairs. Further, if the optional begin
and
end
arguments are specified, the rows will be filter to lie
within that time interval. Furthermore, the first and last day of
each month are computed.
Value
a data.frame
with four variables: year
,
month
, month_begin
(the first day of the month), and
month_end
(the last day of the month).
Examples
valid_year_month(years = 1999:2001, months = c(1:3, 7))
# Mets in the World Series since the UNIX epoch
mets_ws <- c(1969, 1973, 1986, 2000, 2015)
valid_year_month(years = mets_ws, months = 10)
# Mets in the World Series during the Clinton administration
if (require(ggplot2)) {
clinton <- filter(presidential, name == "Clinton")
valid_year_month(years = mets_ws, months = 10,
begin = clinton$start, end = clinton$end)
}