end_of_period: Handling and Manipulating Dates and Times

end_of_periodR Documentation

Handling and Manipulating Dates and Times

Description

Functions for manipulating vectors that inherit from class POSIXt or Date.

Usage

is_leapyear(x)

first_of_month(x)
end_of_month(x, shift = 0L)
end_of_previous_month(x)

first_of_year(x)
end_of_year(x, shift = 0L)
end_of_previous_year(x)

end_of_quarter(x, shift = 0L)

day_of_month(x)
day_of_month(x) <- value
mday(x)
mday(x) <- value

second(x, as.character = FALSE)
minute(x, as.character = FALSE)
hour(x, as.character = FALSE)
month(x, as.character = FALSE)
year(x, as.character = FALSE)

Arguments

x

a vector of class Date

value

a vector of integers

shift

integer

as.character

logical

Details

end_of_month returns the last calendar day of a given month. If shift is positive, then shift months into the future; if negative, the end of previous months. end_of_month(x, -1) is equivalent to end_of_previous_month(x). end_of_year works in the same way, but for calendar years.

mday is a wrapper for day_of_month.

Value

Vectors of class Date or POSIXct; or logical

Author(s)

Enrico Schumann

References

B.D. Ripley and K. Hornik. Date-Time Classes. R-News, 1(2):8–12, 2001.

See Also

DateTimeClasses

Many useful functions are also in package chron.

Examples

## vectorisation: x *or* shift (but not both!)
end_of_month(as.Date("2013-01-15"), shift = c(-1, 0, 1))
end_of_month(as.Date("2013-01-15") + 0:100)


day_of_month(d <- as.Date("2013-01-22"))
day_of_month(d) <- 5
d

enricoschumann/datetimeutils documentation built on April 2, 2024, 11:10 a.m.