Learn R Programming

mondate (version 0.9.10.01)

year-month-day-methods: Useful Methods for Class mondate

Description

The methods in this section facilitate mondate construction using the year, month, and day numbers of the date (as those numbers would be seen in the character representation of the date, i.e.., "January" = 1 and the first day of a month = 1).

Usage

year(x, ...)
month(x, ...)
day(x, ...)
ymd(x)

mondate.mdy(m, d, y, displayFormat=.default.displayFormat,
            timeunits=.default.timeunits, ...)

mondate.ymd(y, m, d, displayFormat=.default.displayFormat,
            timeunits=.default.timeunits, ...)

Arguments

x
an object of class "mondate."
m
the month: 1, ..., 12. If "missing" and d is also "missing", m=12 by default.
d
the day: 1, ..., 31, depending on the month. If "missing" in the case of mondate.ymd, the last day of the month is inserted.
y
the four-digit year.
displayFormat
the date format with which to display the mondate.
timeunits
character string "months" (default), "years", or "days" indicating the units in which date arithmetic will be carried out.
...
For year, month, and day, not used. For mondate.mdy and mondate.ymd arguments to be passed to the mondate constructor.

Value

  • year returns the year number (e.g., 2000) as a numeric. month returns the month number (1, ..., 12) as a numeric. day returns the day of the month as a numeric starting with 1. ymd returns a matrix with the number of rows equal to the length of x and with appropriately-named columns 1 through 3 holding the year, month, and day, respectively. mondate.mdy and mondate.ymd return "mondates" with the given month, day, and year. Arguments m, d, and y may have length > 1; the usual recycling rules apply. The mondate.ymd function has a bit more functionality. If d is "missing" in a call to mondate.ymd then the date returned will be the last day of month m in year y. If m is also missing, then the date returned will be the last day of the year. If any of y, m, or d are NA the result will be an all-NA vector. And if y=+-Inf then the result will be an "infinite" mondate vector, overriding other rules included herein. The length of a vector result is determined using the usual recycling rules as though a valid, finite scalar had been inserted instead of NA or +-Inf. See the Examples section.

Examples

Run this code
M<-mondate.mdy(6,30,2008)
year(M)     # 2008
month(M)    # 6
day(M)      # 30
mondate.ymd(2008,6,30)  # ditto
mondate.ymd(2008,6)     # ditto; 'day' argument is "missing" so
                        # returns the last day of the month
mondate.ymd(2008,1:12)  # all month-ends of 2008, a leapyear
# year-ends 2001 through 2010, displaying only the 4-digit year when shown
mondate.ymd(2001:2010, displayFormat="%Y")
mondate.ymd(2010:2012, NA) # NA mondate vector of length 3
mondate.ymd(Inf,11,31)  # An infinite mondate even though only 30 days in 
                        # November

Run the code above in your browser using DataLab