I am trying to generate an xts objet based on intraday data of 5 min spam. The problem comes when transforming the date-time into a POSIXct object. By doing it, it activates the daylight saving time, and my format changes. When creating the object the differences in format create NAs, and my cts object is not generated.
I read the data from my csv file
data = fread("….csv", header = T, sep = ",")
Take the date-time and store it in one variable
time <- data[,1]
This is how my dates look like
data[,1]
[844] "03.01.2019 22:15:00.000 GMT+0100" "03.01.2019 22:20:00.000 GMT+0100" "03.01.2019 22:25:00.000 GMT+0100" [847] "03.01.2019 22:30:00.000 GMT+0100" "03.01.2019 22:35:00.000 GMT+0100" "03.01.2019 22:40:00.000 GMT+0100" [850] "03.01.2019 22:45:00.000 GMT+0100" "03.01.2019 22:50:00.000 GMT+0100" "03.01.2019 22:55:00.000 GMT+0100" [853] "03.01.2019 23:00:00.000 GMT+0100" "03.01.2019 23:05:00.000 GMT+0100" "03.01.2019 23:10:00.000 GMT+0100" [856] "03.01.2019 23:15:00.000 GMT+0100" "03.01.2019 23:20:00.000 GMT+0100" "03.01.2019 23:25:00.000 GMT+0100" [859] "03.01.2019 23:30:00.000 GMT+0100" "03.01.2019 23:35:00.000 GMT+0100" "03.01.2019 23:40:00.000 GMT+0100" [862] "03.01.2019 23:45:00.000 GMT+0100" "03.01.2019 23:50:00.000 GMT+0100" "03.01.2019 23:55:00.000 GMT+0100" [865] "04.01.2019 00:00:00.000 GMT+0100" "04.01.2019 00:05:00.000 GMT+0100" "04.01.2019 00:10:00.000 GMT+0100" [868] "04.01.2019 00:15:00.000 GMT+0100" "04.01.2019 00:20:00.000 GMT+0100" "04.01.2019 00:25:00.000 GMT+0100" [871] "04.01.2019 00:30:00.000 GMT+0100" "04.01.2019 00:35:00.000 GMT+0100" "04.01.2019 00:40:00.000 GMT+0100" [874] "04.01.2019 00:45:00.000 GMT+0100" "04.01.2019 00:50:00.000 GMT+0100" "04.01.2019 00:55:00.000 GMT+0100" [877] "04.01.2019 01:00:00.000 GMT+0100" "04.01.2019 01:05:00.000 GMT+0100" "04.01.2019 01:10:00.000 GMT+0100" [880] "04.01.2019 01:15:00.000 GMT+0100" "04.01.2019 01:20:00.000 GMT+0100" "04.01.2019 01:25:00.000 GMT+0100"
I create the new POSIX variable
x2 <- as.POSIXct(time, format='%m.%d.%Y %H:%M:%S')
my new variable looks like this (you can see the timezone has changed from April)
x2
[845] "2019-03-01 22:20:00 CET" "2019-03-01 22:25:00 CET" "2019-03-01 22:30:00 CET" "2019-03-01 22:35:00 CET" [849] "2019-03-01 22:40:00 CET" "2019-03-01 22:45:00 CET" "2019-03-01 22:50:00 CET" "2019-03-01 22:55:00 CET" [853] "2019-03-01 23:00:00 CET" "2019-03-01 23:05:00 CET" "2019-03-01 23:10:00 CET" "2019-03-01 23:15:00 CET" [857] "2019-03-01 23:20:00 CET" "2019-03-01 23:25:00 CET" "2019-03-01 23:30:00 CET" "2019-03-01 23:35:00 CET" [861] "2019-03-01 23:40:00 CET" "2019-03-01 23:45:00 CET" "2019-03-01 23:50:00 CET" "2019-03-01 23:55:00 CET" [865] "2019-04-01 00:00:00 CEST" "2019-04-01 00:05:00 CEST" "2019-04-01 00:10:00 CEST" "2019-04-01 00:15:00 CEST" [869] "2019-04-01 00:20:00 CEST" "2019-04-01 00:25:00 CEST" "2019-04-01 00:30:00 CEST" "2019-04-01 00:35:00 CEST" [873] "2019-04-01 00:40:00 CEST" "2019-04-01 00:45:00 CEST" "2019-04-01 00:50:00 CEST" "2019-04-01 00:55:00 CEST" [877] "2019-04-01 01:00:00 CEST" "2019-04-01 01:05:00 CEST" "2019-04-01 01:10:00 CEST" "2019-04-01 01:15:00 CEST" [881] "2019-04-01 01:20:00 CEST"
Then I create the xts but the error saying that NAs are generated appears
data.xts <- xts(data[,2], order.by = x2)
Error in xts(data[, 2], order.by = x2) : 'order.by' cannot contain 'NA', 'NaN', or 'Inf'