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 Monday, Wednesday, or Friday.
In R, the seq command can be used with dates easily.
fall_dates <- seq(as.Date("2017-08-23"), as.Date("2017-12-08"), 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(fall_dates)), order.by = fall_dates)
For instance, I want to know the exact dates for each Monday, Wednesday, and Friday of the semester. The convention here is that “0” is a Monday and “7” is a Sunday.
MWF_dates <- xts_dates[.indexwday(xts_dates) %in% c(0, 2, 4)]
head(MWF_dates)
## [,1]
## 2017-08-23 NA
## 2017-08-25 NA
## 2017-08-28 NA
## 2017-08-30 NA
## 2017-09-01 NA
## 2017-09-04 NA
From here, I might still want to use Excel for data entry in my planning. xts objects are still zoo objects.
write.zoo(MWF_dates, sep = ",", file = "schedule.csv")
Now I have a spreadsheet with the dates already arranged!