Skip to content

Table of Contents

Dates can be fussy. (Especially when they come to you mangled by manual formatting in spreadsheets.)

Sometimes it’s easier, when there are consecutive dates, simply to create them with seq. For ts, don’t even bother, just use object <- ts(source, start = c(2018,1 ) ...)

The date can be unpacked multiple ways to make presentation easier. Here’s what can be done with days of the week.

suppressPackageStartupMessages(library(lubridate))
seq(c(ISOdate(2020,7,19)), by = "day", length.out = 7) -> the_days

wday(the_days)
## [1] 1 2 3 4 5 6 7
wday(the_days, label = TRUE)
## [1] Sun Mon Tue Wed Thu Fri Sat
## Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
wday(the_days, label = TRUE, abbr = FALSE)
## [1] Sunday    Monday    Tuesday   Wednesday Thursday  Friday    Saturday 
## 7 Levels: Sunday < Monday < Tuesday < Wednesday < Thursday < ... < Saturday
# locale argument is OS specific
wday(the_days, label = TRUE, abbr = FALSE, locale = "fr_FR.utf8")
## [1] dimanche lundi    mardi    mercredi jeudi    vendredi samedi  
## 7 Levels: dimanche < lundi < mardi < mercredi < jeudi < ... < samedi

Latest

Counting chickens

Counting chickens

Refining polling models. It's the received wisdom of the ages—don't rely on events that haven't happened yet. On the other hand, don't bring a knife to a gunfight, either.

Members Public