set_year: Alter the year in a POSIX-Object or Series

View source: R/set_year.r

set_yearR Documentation

Alter the year in a POSIX-Object or Series

Description

Alter the year in a POSIX object or a vector of such objects

Usage

set_year(x, year = NULL)

Arguments

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

Details

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.

Value

A POSIX object or a vector of POSIX objects

Author(s)

Simon Frey

Examples

    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)
    
    #################################

freysimon/TigR documentation built on April 20, 2024, 9:28 p.m.