Date arithmetic

# R knows the lengths of months, e.g. that March has 31 days:
d0 <- as.Date("1968-03-01")
d0 + 31
[1] "1968-04-01"
# R also knows that 1968 was a leap year,
d1 <- as.Date("1968-02-28")
d1 + 1
[1] "1968-02-29"
# that 1900 was not a leap year,
d2 <- as.Date("1900-02-28")
d2 + 1
[1] "1900-03-01"
# that 2000 was a leap year,
d3 <- as.Date("2000-02-28")
d3 + 1
[1] "2000-02-29"
# and that leap years are 366 days long
d3 + 366
[1] "2001-02-28"

Downloadable R script and interactive version


The link with the “jupyterhub” icon directs you to an interactive Jupyter1 notebook, which runs inside a Docker container2. There are two variants of the interative notebook. One shuts down after 60 seconds and does not require a sign it. The other requires sign in using your ORCID3 credentials, yet shuts down only after 24 hours. (There is no guarantee that such a container persists that long, it may be shut down earlier for maintenance purposes.) After shutdown all data within the container will be reset, i.e. all files created by the user will be deleted.4

Above you see a rendered version of the Jupyter notebook.5


For more information about Jupyter see The Jupyter notebooks make use of the RKernel package.


For more information about Docker see The container images are run with docker spawner.


ORCID is a free service for the authentication of researchers. It also allows to showcase publications and contributions to the academic community such as peer review.. See for more information.


The Jupyter notebooks come with NO WARRANTY whatsoever. They are provided for educational and illustrative purposes only. Do not use them for production work.


The notebook is rendered with the help of the nbsphinx extension.