Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ymd

Extract parts of various Date-Time Objects


Description

Extract the year, month or day, or all three (in yyyymmdd form), or the quarter, from a jul, ti, or from any object that jul() can handle.

Usage

ymd(x, ...)
## S3 method for class 'jul'
ymd(x, ...)
## S3 method for class 'ssDate'
ymd(x, ...)
## S3 method for class 'ti'
ymd(x, offset = 1, ...)
## Default S3 method:
ymd(x, ...)
year(x, ...)
quarter(x, ...)
month(x, ...)
day(x, ...)

Arguments

x

a ti or jul, or something that jul() can create a jul object from.

...

other args to be passed to the method called by the generic function. year, quarter, month, day and ymd.default may pass these args to as.Date.

offset

for ti x, a number in the range [0,1] telling where in the period represented by x to find the day. 0 returns the first day of the period, while the default value 1 returns the last day of the period. For example, if x has tif = "wmonday" so that x represents a week ending on Monday, than any offset in the range [0, 1/7] will return the Tuesday of that week, while offset in the range (1/7, 2/7] will return the Wednesday of that week, offset in the range (6/7, 1] will return the Monday that ends the week, and so on.

Details

year, quarter, month and day call ymd, and thus understand the same arguments as it does. The default implementation ymd.default passes it's arguments to a call to the function jul, so all of these functions work the same way that function does.

Value

ymd and it's variants return numeric objects in yyyymmdd form.

year, quarter, month and day return numeric objects.

ymd() with no arguments returns today's yyyymmdd.

See Also

Examples

ymd()                            ## today's date and time
weekFromNow <- ymd(today() + 7)  ## today() returns a daily ti
year(jul(today()))
month(Sys.time())
## create a monthly tis (Time Indexed Series)
aTis <- tis(0, start = c(2000, 1), end = c(2004, 12), freq = 12)
ymd(ti(aTis))                    ## the yyyymmdd dates of the observations

tis

Time Indexes and Time Indexed Series

v1.38
Unlimited
Authors
Jeff Hallman <jeffhallman@gmail.com>
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.