Skip to content

Instantly share code, notes, and snippets.

@npjc
Created April 24, 2017 17:23
Show Gist options
  • Save npjc/0e1044f12db8801bfcce205ef87d8040 to your computer and use it in GitHub Desktop.
Save npjc/0e1044f12db8801bfcce205ef87d8040 to your computer and use it in GitHub Desktop.
calendar week rows csv
year cw month Sun Mon Tues Wed Thurs Fri Sat
2017 2 Jan 1 2 3 4 5 6 7
2017 3 Jan 8 9 10 11 12 13 14
2017 4 Jan 15 16 17 18 19 20 21
2017 5 Jan 22 23 24 25 26 27 28
2017 6 Jan 29 30 31
2017 6 Feb 1 2 3 4
2017 7 Feb 5 6 7 8 9 10 11
2017 8 Feb 12 13 14 15 16 17 18
2017 9 Feb 19 20 21 22 23 24 25
2017 10 Feb 26 27 28
2017 10 Mar 1 2 3 4
2017 11 Mar 5 6 7 8 9 10 11
2017 12 Mar 12 13 14 15 16 17 18
2017 13 Mar 19 20 21 22 23 24 25
2017 14 Mar 26 27 28 29 30 31
2017 14 Apr 1
2017 15 Apr 2 3 4 5 6 7 8
2017 16 Apr 9 10 11 12 13 14 15
2017 17 Apr 16 17 18 19 20 21 22
2017 18 Apr 23 24 25 26 27 28 29
2017 19 Apr 30
2017 19 May 1 2 3 4 5 6
2017 20 May 7 8 9 10 11 12 13
2017 21 May 14 15 16 17 18 19 20
2017 22 May 21 22 23 24 25 26 27
2017 23 May 28 29 30 31
2017 23 Jun 1 2 3
2017 24 Jun 4 5 6 7 8 9 10
2017 25 Jun 11 12 13 14 15 16 17
2017 26 Jun 18 19 20 21 22 23 24
2017 27 Jun 25 26 27 28 29 30
2017 27 Jul 1
2017 28 Jul 2 3 4 5 6 7 8
2017 29 Jul 9 10 11 12 13 14 15
2017 30 Jul 16 17 18 19 20 21 22
2017 31 Jul 23 24 25 26 27 28 29
2017 32 Jul 30 31
2017 32 Aug 1 2 3 4 5
2017 33 Aug 6 7 8 9 10 11 12
2017 34 Aug 13 14 15 16 17 18 19
2017 35 Aug 20 21 22 23 24 25 26
2017 36 Aug 27 28 29 30 31
2017 36 Sep 1 2
2017 37 Sep 3 4 5 6 7 8 9
2017 38 Sep 10 11 12 13 14 15 16
2017 39 Sep 17 18 19 20 21 22 23
2017 40 Sep 24 25 26 27 28 29 30
2017 41 Oct 1 2 3 4 5 6 7
2017 42 Oct 8 9 10 11 12 13 14
2017 43 Oct 15 16 17 18 19 20 21
2017 44 Oct 22 23 24 25 26 27 28
2017 45 Oct 29 30 31
2017 45 Nov 1 2 3 4
2017 46 Nov 5 6 7 8 9 10 11
2017 47 Nov 12 13 14 15 16 17 18
2017 48 Nov 19 20 21 22 23 24 25
2017 49 Nov 26 27 28 29 30
2017 49 Dec 1 2
2017 50 Dec 3 4 5 6 7 8 9
2017 51 Dec 10 11 12 13 14 15 16
2017 52 Dec 17 18 19 20 21 22 23
2017 53 Dec 24 25 26 27 28 29 30
2017 54 Dec 31
2018 1 Jan 1
library(tidyverse)
library(lubridate)
# function to get calendar week -------------------------------------------
# copied and modified from:
# http://stackoverflow.com/questions/27116645/r-week-function-returns-unexpected-values
calendar_week <- function(x){
# fst monday of the same year
first_sun <- as.POSIXct(paste0(year(x),"-01-Mon"), format = "%Y-%U-%a")
((yday(x) + (7 - yday(first_sun) + 1)) %/% 7) + 1
}
from <- "2017-01-01"
to <- "2018-01-01"
days <- seq(as_date(from), as_date(to), by = 1)
tibble(day = days,
year = year(day),
cw = calendar_week(day),
month = month(day, label = T),
monthday = mday(day),
weekday = wday(day, label = T)) %>%
group_by(year, cw, month) %>%
select(-day) %>%
spread(weekday, monthday, fill = '') %>%
write_csv("cal-sheet.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment