time_shift adds days, weeks, months, quarters or years to dates.
date_month, date_quarter and date_year return the first day of the
period and are useful for customized aggregation of data frames. For standard
aggregation, use ts_frequency().
time_shift(x, by = NULL) date_month(x) date_quarter(x) date_year(x)
| x |
|
|---|---|
| by | passed on to |
an object of class Date
ts_frequency() for standard aggregation. time_shift(), for
shifting time stamps of a ts-boxable object.
#> [1] "1949-01-01" "1949-02-01" "1949-03-01" "1949-04-01" "1949-05-01" #> [6] "1949-06-01"head(date_month(ap.time))#> [1] "1949-01-01" "1949-02-01" "1949-03-01" "1949-04-01" "1949-05-01" #> [6] "1949-06-01"head(date_year(ap.time))#> [1] "1949-01-01" "1949-01-01" "1949-01-01" "1949-01-01" "1949-01-01" #> [6] "1949-01-01"head(time_shift(ap.time, 14))#> [1] "1949-01-15" "1949-02-15" "1949-03-15" "1949-04-15" "1949-05-15" #> [6] "1949-06-15"head(time_shift(ap.time, "7 week"))#> [1] "1949-02-19" "1949-03-22" "1949-04-19" "1949-05-20" "1949-06-19" #> [6] "1949-07-20"head(time_shift(ap.time, "-1 month"))#> [1] "1948-12-01" "1949-01-01" "1949-02-01" "1949-03-01" "1949-04-01" #> [6] "1949-05-01"