LoslegenKostenlos loslegen

How many seconds are in a day?

How many seconds are in a day? There are 24 hours in a day, 60 minutes in an hour, and 60 seconds in a minute, so there should be 24*60*60 = 86400 seconds, right?

Not always! In this exercise you'll see a counter example, can you figure out what is going on?

Diese Übung ist Teil des Kurses

Working with Dates and Times in R

Kurs anzeigen

Anleitung zur Übung

We've put code to define three times in your script - noon on March 11th, March 12th, and March 13th in 2017 in the US Pacific timezone.

  • Find the difference in time between mar_13 and mar_12 in seconds. This should match your intuition.
  • Now, find the difference in time between mar_12 and mar_11 in seconds. Surprised?

Interaktive Übung

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

# Three dates
mar_11 <- ymd_hms("2017-03-11 12:00:00", 
  tz = "America/Los_Angeles")
mar_12 <- ymd_hms("2017-03-12 12:00:00", 
  tz = "America/Los_Angeles")
mar_13 <- ymd_hms("2017-03-13 12:00:00", 
  tz = "America/Los_Angeles")

# Difference between mar_13 and mar_12 in seconds
difftime(___, ___, units = ___)

# Difference between mar_12 and mar_11 in seconds
difftime(___, ___, units = ___)
Code bearbeiten und ausführen