Rotunjirea datelor și orelor

Lucrul cu date și ore în R

Charlotte Wickham

Instructor

Rotunjire versus extragere

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"
Lucrul cu date și ore în R

Rotunjire în lubridate

  • round_date() - rotunjire la cel mai apropiat
  • ceiling_date() - rotunjire în sus
  • floor_date() - rotunjire în jos
  • Valori posibile ale unit:
    • "second", "minute", "hour", "day", "week", "month", "bimonth", "quarter", "halfyear", sau "year".
    • Sau multipli, de ex. "2 years", "5 minutes"
Lucrul cu date și ore în R

Să exersăm!

Lucrul cu date și ore în R

Preparing Video For Download...