nth_day {datetimeutils} | R Documentation |
Compute Reference Dates
Description
Compute sequences of reference dates, such as last day of month or first day of quarter.
Usage
nth_day(timestamps, period = "month", n,
start, end, business.days = FALSE,
missing = "previous", index = FALSE)
Arguments
timestamps |
timestamps: a sorted vector of Dates |
period |
numeric or character: supported are |
n |
numeric or character: currently supported are
|
start |
|
end |
|
business.days |
logical |
missing |
character. Not supported yet. |
index |
logical. If |
Details
The function computes sequences of dates that are often used as reference dates, for instance in financial reporting: last day of the month or of the year, or a particular day of the month.
The function takes a vector of timestamps and returns
a subset of these timestamps. Alternatively, a
sequence of calendar days may be constructed by
specifying start
and end
.
Value
A vector of timestamps or, if index
is
TRUE
, a vector of integers.
Author(s)
Enrico Schumann
See Also
Examples
timestamps <- seq(from = as.Date("2001-01-01"),
to = as.Date("2001-04-15"),
by = "1 day")
nth_day(timestamps, period = "quarter", n = "last")
## [1] "2001-03-31" "2001-04-15"
nth_day(timestamps, period = "quarter", n = 10)
## [1] "2001-01-10" "2001-04-10"
nth_day(timestamps, period = "quarter", n = 1:2)
## [1] "2001-01-01" "2001-01-02" "2001-04-01" "2001-04-02"
nth_day(timestamps, period = "month", n = "last")
## [1] "2001-01-31" "2001-02-28" "2001-03-31" "2001-04-15"
nth_day(start = as.Date("2016-06-03"),
end = as.Date("2017-08-01"),
period = c(6, 12), n = 3)
## [1] "2016-06-05" "2016-12-03" "2017-06-03"
nth_day(start = as.Date("2016-06-03"),
end = as.Date("2017-08-01"),
period = c("Jun", "Dec"), n = c(3, 5))
## [1] "2016-06-05" "2016-06-07" "2016-12-03" "2016-12-05"
## [5] "2017-06-03" "2017-06-05"