# NOT RUN {
# At the beginning of your analysis, set the week start to the weeks you want
# to use for reporting
ow <- set_week_start("Sunday")
# convert dates to weeks
d <- as.Date(c("2014-02-11", "2014-03-04"))
w <- as.aweek(d)
w
# get the week numbers
date2week(d, numeric = TRUE)
# convert back to date
as.Date(w)
# convert to factor
factor_aweek(w)
# append a week
w[3] <- as.Date("2014-10-31")
w
# change week start variable (if needed)
change_week_start(w, "Monday")
# note that the date remains the same
as.Date(change_week_start(w, "Monday"))
# Don't forget to reset the week_start at the end
set_week_start(ow)
# }
Run the code above in your browser using DataLab