LoslegenKostenlos loslegen

Fast parsing with lubridate::fast_strptime

lubridate provides its own fast datetime parser: fast_strptime(). Instead of taking an order argument like parse_date_time() it takes a format argument and the format must comply with the strptime() style.

As you saw in the video that means any character that represents a datetime component must be prefixed with a % and any non-whitespace characters must be explicitly included.

Try parsing dates with fast_strptime() and then compare its speed to the other methods you've seen.

Diese Übung ist Teil des Kurses

Working with Dates and Times in R

Kurs anzeigen

Anleitung zur Übung

dates is in your workspace again.

  • Examine the head of dates. What components are present? What separators are used?
  • Parse dates with fast_strptime() by specifying the appropriate format string.
  • Compare the timing of fast_strptime() to fasttime and ymd_hms().

Interaktive Übung

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

# Head of dates
head(___)

# Parse dates with fast_strptime
fast_strptime(dates, 
    format = ___) %>% str()

# Comparse speed to ymd_hms() and fasttime
microbenchmark(
  ymd_hms = ymd_hms(dates),
  fasttime = fastPOSIXct(dates),
  fast_strptime = ___(dates, 
    format = ___),
  times = 20)
Code bearbeiten und ausführen