Coerce an aweek object to factor to include missing weeks

factor_aweek(x)

Arguments

x

an aweek object

Value

an aweek object that inherits from factor() with levels that span the range of the weeks in the object.

Note

when factored aweek objects are combined with other aweek objects, they are converted back to characters.

Examples

w <- get_aweek(week = (1:2) * 5, year = 2019, day = c(7, 1)) w
#> <aweek start: Monday> #> [1] "2019-W05-7" "2019-W10-1"
wf <- factor_aweek(w) wf
#> <aweek start: Monday> #> [1] 2019-W05 2019-W10 #> Levels: 2019-W05 2019-W06 2019-W07 2019-W08 2019-W09 2019-W10
# factors are destroyed if combined with aweek objects c(w, wf)
#> <aweek start: Monday> #> [1] "2019-W05-7" "2019-W10-1" "2019-W05-1" "2019-W10-1"