LoslegenKostenlos loslegen

Arithmetic and logical operators

Since Date objects are internally represented as the number of days since 1970-01-01 you can do basic math and comparisons with dates. You can compare dates with the usual logical operators (<, ==, > etc.), find extremes with min() and max(), and even subtract two dates to find out the time between them.

In this exercise you'll see how these operations work by exploring the last R release. You'll see Sys.date() in the code, it simply returns today's date.

Diese Übung ist Teil des Kurses

Working with Dates and Times in R

Kurs anzeigen

Anleitung zur Übung

  • Find the date of the most recent release by calling max() on the date column in releases.
  • Find the rows in releases that have the most recent date, by specifying the comparison date == last_release_date in filter().
  • Print last_release to see which release this was.
  • Calculate how long it has been since the most recent release by subtracting last_release_date from Sys.Date().

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Find the largest date
last_release_date <- max(___)

# Filter row for last release
last_release <- filter(releases, ___)

# Print last_release
last_release

# How long since last release?
Sys.Date() - ___
Code bearbeiten und ausführen