mondate (version 0.10.01.02)

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

Description

The methods in this section facilitate year-, month-, day-, and quarter-number extraction from objects that represent dates, as well as 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, ...) quarter(x, ...) ymd(x)
mondate.mdy(m, d, y, ...)
mondate.ymd(y, m, d, ...)

Arguments

x
an object of class mondate, Date, or POSIXt
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.
...
For year, month, and day, not used. For mondate.mdy and mondate.ymd arguments to be passed to the mondate constructor, e.g., displayFormat and timeunits.

Value

year returns the year numeric (e.g., 2000).month returns the month numeric 1, ..., 12.day returns the numeric day of the month.quarter returns the numeric calendar quarter of the year: 1 for January - March, 2 for April - June, etc.ymd returns a matrix with the number of rows equal to the length of x, with appropriately-named columns 1 through 3 holding the year, month, and day, respectively and with "rownames" equal to names(x).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 2013, displaying only the 4-digit year when shown
mondate.ymd(2001:2013, 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
                        
x <- mondate.ymd(2013, 1:12) # month-ends in 2013
# Give x some shape
dim(x) <- 3:4
dimnames(x) <- list(A = letters[1:3], B = LETTERS[1:4])
# Return the quarter numbers in an array with the same shape and dimnames
quarter(x) 

Run the code above in your browser using DataCamp Workspace