The methods in this section facilitate
year-, month-, day-, and quarter-number extraction from objects that represent dates,
as well as
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).
1 2 3 4 5 6 7 8 9
an object of class
the month: 1, ..., 12.
If "missing" and
the day: 1, ..., 31, depending on the month.
If "missing" in the case of
the four-digit year.
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
columns 1 through 3 holding the
and with "rownames" equal to
mondates with the given
month, day, and year.
y may have length > 1;
the usual recycling rules apply.
mondate.ymd function has a bit more functionality.
d is "missing" in a call to
mondate.ymd then the date
returned will be the last day of month
m in year
m is also missing,
then the date returned will be the last day of the year.
If any of
the result will be an all-
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
See the Examples section.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.