| time-index-components | R Documentation |
The following functions can be used to retrieve components of time indices.
year, quarter, month, week, day return
year (0–9999), quarter (1–4), month (1–12), week (1–53, ISO 8601),
and day (1–31) indices as integers. When month is invoked
with labels argument set to TRUE, an ordered factor is returned.
day_of_week returns index (1–7) of weekday with Monday as the first
day (as in ISO 8601). When invoked with labels argument
set to TRUE, an ordered factor is returned.
day_of_year returns index (1–366) of the day of year as integer.
hour, minute, second return hour (0–23),
minute (0–59), and second (0–59,999999) indices as integers and reals (for seconds).
am and pm functions determine whether time falls in the first
or second half of the day.
Methods weekdays, months, and quarters from package base
are implemented but users are encouraged to use functions from tind package.
year(x)
quarter(x)
## S3 method for class 'tind'
quarters(x, abbreviate)
month(x, labels = FALSE, abbreviate = TRUE, locale = NULL)
## S3 method for class 'tind'
months(x, abbreviate = FALSE)
week(x)
day(x)
day_of_year(x)
day_of_week(x, labels = FALSE, abbreviate = TRUE, locale = NULL)
## S3 method for class 'tind'
weekdays(x, abbreviate = FALSE)
hour(x)
am(x)
pm(x)
minute(x)
second(x)
x |
an object of |
abbreviate |
a logical value, if |
labels |
a logical value, if |
locale |
(optional) a character value determining locale or |
year for week arguments need not necessarily return the same value
as for days within the week in question when the week is the first or the last
in a year.
tind package does not provide replacement methods for time index components.
In order to change, say, month one can use tind constructor or %+m%
operator (and similar operators), see Examples.
All functions return integer vectors, except for second, which
returns numeric vectors. Additionally, month and day_of_week
return ordered factors if invoked with argument labels set to TRUE.
tind class, Ops
for index increments / decrements and index differences, and
calendar-names for names of months and days of weeks in the current
locale. Further examples of use of these functions can be found
in calendar documentation.
# current date and time
(nw <- now())
# show current year, quarter, month, ...
year(nw)
quarter(nw)
month(nw)
month(nw, labels = TRUE)
month(nw, labels = TRUE, abbreviate = FALSE)
week(nw)
day(nw)
day_of_week(nw)
day_of_week(nw, labels = TRUE)
day_of_week(nw, labels = TRUE, abbreviate = FALSE)
day_of_year(nw)
hour(nw)
minute(nw)
second(nw)
# alternatives to replacement, change month to December
(x <- as.date("2023-09-11"))
(x <- tind(y = year(x), m = 12, d = day(x)))
(x <- as.date("2023-09-11"))
(x <- x %+m% (12 - month(x)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.