0

I am pretty new to R, so maybe my question is not clear from the start, but I've a problem using the ymd_hms function of the lubridate package in R. I am trying to test the functionality of dygraph. I've a large dataset of temperature values with a interval of one hour. There's one specific timestamp which seem to pose the problem, which is : 2017/3/26 02:00:00

This is a sample of the dataset (called "weerdata.csv") to show you :

Meetdatum,Temperatuur 2017/3/26 01:00:00,11.10 2017/3/26 02:00:00,13.70 2017/3/26 03:00:00,14.90 2017/3/26 04:00:00,16.30

This is the code I am executing in the R console :

weerdata <- read.csv("F:/_data/gegevensverwerking/R/TESTSR/data/weerdata.csv") weerdata$Meetdatum<- ymd_hms(weerdata$Meetdatum,tz=Sys.timezone()) time_series <- xts(weerdata, order.by = weerdata$Meetdatum) dygraph(time_series) %>% dyRangeSelector()

The error that I receive is : Error in xts::periodicity(data) : can not calculate periodicity of 1 observation

The problem is that 2017/3/26 02:00:00 is converted to NULL with the ymd_hms function. This problem does not occur when using for instance this dataset :

Meetdatum,Temperatuur 2017/3/26 11:00:00,11.10 2017/3/26 12:00:00,13.70 2017/3/26 13:00:00,14.90 2017/3/26 14:00:00,16.30

I've temperature values in my dataset from 2017/1/1 01:00:00 until 2017/5/28 09:00:00, and the only one that is posing a problem is 2017/3/26 02:00:00.

Does anyone has an idea ?

Thank you very much in advance.

Stijn, Belgium

  • Can you show the version of `lubridate`? It is working for me `ymd_hms("2017/3/26 02:00:00") #[1] "2017-03-26 02:00:00 UTC"` with `lubridate_1.6.0`. Also tried with `xts`, it is not showing any NULL for me – akrun Jun 13 '17 at 12:21

1 Answers1

0

That type of question comes up every once in a while but I don't have time to find duplicate.

Most likely this has to do with daylight savings time: in your timezone, that 02:00 hour did not exist: "spring forward". See a quick illustration:

R> library(anytime)
R> anytime(paste("2017/03/26", c("01:00", "02:00", "03:00", "04:00")))  # Europe 
[1] "2017-03-26 01:00:00 CDT" "2017-03-26 02:00:00 CDT" 
[3] "2017-03-26 03:00:00 CDT" "2017-03-26 04:00:00 CDT"
R> anytime(paste("2017/03/12", c("01:00", "02:00", "03:00", "04:00")))  # US 
[1] "2017-03-12 01:00:00 CST" "2017-03-12 01:00:00 CST" 
[3] "2017-03-12 03:00:00 CDT" "2017-03-12 04:00:00 CDT"
R> 

See how for me (in Central time) I get 01:00 twice?

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725