Learn R Programming

datetimeutils (version 0.6-4)

end_of_period: 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)

Value

Vectors of class Date or POSIXct; or logical

Arguments

x

a vector of class Date

value

a vector of integers

shift

integer

as.character

logical

Author

Enrico Schumann

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.

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

Run this code
## 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

Run the code above in your browser using DataLab