Get startedGet started for free

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.

This exercise is part of the course

Working with Dates and Times in R

View Course

Exercise instructions

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().

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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)
Edit and Run Code