Semester Schedule Planner

As a lecturer at UC Merced, each semester I find myself needing to figure out how many days I get to teach. Furthermore, I like to plan out my lecture schedule down to the days themselves. Here I hope to use some R code to quickly figure out (say) which days are on Tuesday or Thursday.

Construction

In R, the seq command can be used with dates easily.

semester_dates <- seq(as.Date("2018-08-22"), as.Date("2018-12-07"), by = "days")

When working with time data, the xts package (“extensible time series”) offers convenient tools for manipulating time series.

library("xts")
xts_dates <- as.xts( rep(NA, length(semester_dates)), order.by = semester_dates)

The convention is that “0” is a Sunday, “1” is a Monday, …, and “5” is a Friday.

Monday and Wednesday

Mondays <- xts_dates[.indexwday(xts_dates) == 1]
head(Mondays)
##            [,1]
## 2018-08-27   NA
## 2018-09-03   NA
## 2018-09-10   NA
## 2018-09-17   NA
## 2018-09-24   NA
## 2018-10-01   NA
MW_dates <- xts_dates[.indexwday(xts_dates) %in% c(1, 3)]
head(MW_dates)
##            [,1]
## 2018-08-22   NA
## 2018-08-27   NA
## 2018-08-29   NA
## 2018-09-03   NA
## 2018-09-05   NA
## 2018-09-10   NA

Tuesday and Thursday

TuTh_dates <- xts_dates[.indexwday(xts_dates) %in% c(2, 4)]
head(TuTh_dates)
##            [,1]
## 2018-08-23   NA
## 2018-08-28   NA
## 2018-08-30   NA
## 2018-09-04   NA
## 2018-09-06   NA
## 2018-09-11   NA

Friday

Fri_dates <- xts_dates[.indexwday(xts_dates) == 5]
head(Fri_dates)
##            [,1]
## 2018-08-24   NA
## 2018-08-31   NA
## 2018-09-07   NA
## 2018-09-14   NA
## 2018-09-21   NA
## 2018-09-28   NA

Exporting the Time Series

From here, I might still want to use Excel for data entry in my planning. xts objects are still zoo objects.

#write.zoo(Mondays, sep = ",", file = "schedule.csv")
#write.zoo(MW_dates, sep = ",", file = "schedule.csv")
#write.zoo(TuTh_dates, sep = ",", file = "schedule.csv")
write.zoo(Fri_dates, sep = ",", file = "schedule.csv")

Now I have a spreadsheet with the dates already arranged!