BaşlayınÜcretsiz Başlayın

Converting to durations and periods

Intervals are the most specific way to represent a span of time since they retain information about the exact start and end moments. They can be converted to periods and durations exactly: it's possible to calculate both the exact number of seconds elapsed between the start and end date, as well as the perceived change in clock time.

To do so you use the as.period(), and as.duration() functions, parsing in an interval as the only argument.

Try them out to get better representations of the length of the monarchs reigns.

Bu egzersiz

Working with Dates and Times in R

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Create new columns for duration and period that convert reign into the appropriate object.
  • Examine the name, duration and period columns.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# New columns for duration and period
monarchs <- monarchs %>%
  mutate(
    duration = ___,
    period = ___) 
    
# Examine results    
monarchs %>%
  select(___)
Kodu Düzenle ve Çalıştır