Różnice dat i czasu

Praca z datami i czasem w R

Charlotte Wickham

Instructor

Arytmetyka dat i czasu

  • datetime_1 - datetime2: Odejmowanie – obliczanie czasu, który upłynął
  • datetime_1 + (2 * timespan): Dodawanie i mnożenie – tworzenie dat w przeszłości lub przyszłości
  • timespan1 / timespan2: Dzielenie – zmiana jednostek
Praca z datami i czasem w R

Odejmowanie dat i czasu

releases <- read_csv("rversions.csv")
last_release <- filter(releases, date == max(date))
Sys.Date() - last_release$date
Time difference of 99 days
difftime(Sys.Date(), last_release$date)
Time difference of 99 days

time1 - time2 jest równoważne difftime(time1, time2)

Praca z datami i czasem w R

difftime()

units = "secs", "mins", "hours", "days" lub "weeks"

difftime(Sys.Date(), last_release$date, units = "secs")
Time difference of 8553600 secs
difftime(Sys.Date(), last_release$date, units = "weeks")
Time difference of 14.14286 weeks
Praca z datami i czasem w R

now() i today()

today()
"2017-10-07"
str(today())
 Date[1:1], format: "2017-10-07"
now()
"2017-10-07 09:44:52 PDT"
str(now())
 POSIXct[1:1], format: "2017-10-07 09:44:59"
Praca z datami i czasem w R

Czas na ćwiczenia!

Praca z datami i czasem w R

Preparing Video For Download...