Avrundning av datum och tid

Arbeta med datum och tider i R

Charlotte Wickham

Instructor

Avrundning kontra extrahering

release_time <- releases$datetime
head(release_time)
"1997-12-04 08:47:58 UTC" "1997-12-21 13:09:22 UTC"
"1998-01-10 00:31:55 UTC" "1998-03-14 19:25:55 UTC"
"1998-05-02 07:58:17 UTC" "1998-06-14 12:56:20 UTC"
head(release_time) %>% hour()
8 13  0 19  7 12
head(release_time) %>% floor_date(unit = "hour")
"1997-12-04 08:00:00 UTC" "1997-12-21 13:00:00 UTC"
"1998-01-10 00:00:00 UTC" "1998-03-14 19:00:00 UTC"
"1998-05-02 07:00:00 UTC" "1998-06-14 12:00:00 UTC"
Arbeta med datum och tider i R

Avrundning i lubridate

  • round_date() - avrunda till närmaste
  • ceiling_date() - avrunda uppåt
  • floor_date() - avrunda nedåt
  • Möjliga värden för unit:
    • "second", "minute", "hour", "day", "week", "month", "bimonth", "quarter", "halfyear", eller "year".
    • Eller multiplar, t.ex. "2 years", "5 minutes"
Arbeta med datum och tider i R

Nu kör vi en övning!

Arbeta med datum och tider i R

Preparing Video For Download...