ymd: Extract parts of various Date-Time Objects

Description Usage Arguments Details Value See Also Examples

View source: R/ti.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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

jul, ti, as.Date

Examples

1
2
3
4
5
6
7
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 documentation built on Sept. 29, 2021, 1:06 a.m.