Mai multe despre importul și exportul datelor temporale

Lucrul cu date și ore în R

Charlotte Wickham

Instructor

Parsare rapidă

parse_date_time() poate fi lent, deoarece este conceput să fie permisiv și flexibil.

library(fasttime)
fastPOSIXct("2003-02-27")
"2003-02-26 16:00:00 PST"
Lucrul cu date și ore în R

fast_strptime()

x <- "2001-02-27"

parse_date_time(x, order = "ymd")
"2001-02-27 UTC"
fast_strptime(x, format = "%Y-%m-%d")
"2001-02-27 UTC"
fast_strptime(x, format = "%y-%m-%d")
NA

Consultați Detalii ale format în strptime()

Lucrul cu date și ore în R

Exportul datelor temporale

library(tidyverse)
akl_hourly %>% 
  select(datetime) %>% 
  write_csv("tmp.csv")

tmp.csv

datetime
2016-01-01T00:00:00Z
2016-01-01T00:30:00Z
2016-01-01T01:00:00Z
2016-01-01T01:30:00Z
2016-01-01T02:00:00Z
2016-01-01T02:30:00Z
Lucrul cu date și ore în R

Formatarea datelor temporale

my_stamp <- stamp("Tuesday October 10 2017")
Multiple formats matched: "%A %B %d %y%H"(1), "%A %B %y %d%H"(1), 
"%A %B %d %Y"(1), "%A October %m %y%d"(1), "%A October %m %Y"(0), 
"%A October %H %M%S"(1), "Tuesday %B %d %y%H"(1), "Tuesday %B %y %d%H"(1), 
"Tuesday %B %d %Y"(1), "Tuesday October %m %y%d"(1), 
"Tuesday October %m %Y"(1), "Tuesday October %H %M%S"(1)
Using: "%A %B %d %Y"
my_stamp(ymd("2003-02-27"))
"Thursday February 27 2003"
my_stamp
function(x) 
format(x, format = "%A %B %d %Y")
<environment: 0x1086ed780>
Lucrul cu date și ore în R

Să exersăm!

Lucrul cu date și ore în R

Preparing Video For Download...