Date-setters | R Documentation |
These are Date methods for the setter generics.
set_year()
sets the year.
set_month()
sets the month of the year. Valid values are in the range
of [1, 12]
.
set_day()
sets the day of the month. Valid values are in the range
of [1, 31]
.
## S3 method for class 'Date'
set_year(x, value, ..., invalid = NULL)
## S3 method for class 'Date'
set_month(x, value, ..., invalid = NULL)
## S3 method for class 'Date'
set_day(x, value, ..., invalid = NULL)
x |
A Date vector. |
value |
The value to set the component to. For |
... |
These dots are for future extensions and must be empty. |
invalid |
One of the following invalid date resolution strategies:
Using either If If |
x
with the component set.
x <- as.Date("2019-02-01")
# Set the day
set_day(x, 12:14)
# Set to the "last" day of the month
set_day(x, "last")
# You cannot set a Date to an invalid day like you can with
# a year-month-day. Instead, the default strategy is to error.
try(set_day(x, 31))
set_day(as_year_month_day(x), 31)
# You can resolve these issues while setting the day by specifying
# an invalid date resolution strategy with `invalid`
set_day(x, 31, invalid = "previous")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.