set_year | R Documentation |
Alter the year in a POSIX object or a vector of such objects
set_year(x, year = NULL)
x |
a POSIX object or a vector of such objects |
year |
character or character vector. The "new" year that the new POSIX object(s) will be hold |
If year == NULL the year of Sys.Date will be used. Note, that, if year is a single character value, it is interpreted as the first value in case that x is a vector.
A POSIX object or a vector of POSIX objects
Simon Frey
x <- as.POSIXct(c("2022-12-30","2022-12-31","2023-01-01","2023-01-02"))
year <- "2023"
set_year(x, year)
#################################
x <- as.POSIXct("2021-01-01")
year <- "2023"
set_year(x,year)
#################################
x <- as.POSIXct(c("2022-12-30","2022-12-31","2023-01-01","2023-01-02"))
year <- c("2023","2023","2024","2024")
set_year(x,year)
#################################
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.