在r中的时间序列中拆分时间间隔
我有一个数据集-时间序列 数据如下:在r中的时间序列中拆分时间间隔,r,time,split,R,Time,Split,我有一个数据集-时间序列 数据如下: Col 1(End): 2018.01.01 01:00:00 2018.01.01 02:00:00 2018.01.01 03:00:00 2018.01.01 04:00:00 2018.01.01 05:00:00 2018.01.01 06:00:00 2018.01.01 07:00:00 2018.01.01 08:00:00 2018.01.01 09:00:00 2018.01.01 10:00:00 2018.01.01 11:00:0
Col 1(End):
2018.01.01 01:00:00
2018.01.01 02:00:00
2018.01.01 03:00:00
2018.01.01 04:00:00
2018.01.01 05:00:00
2018.01.01 06:00:00
2018.01.01 07:00:00
2018.01.01 08:00:00
2018.01.01 09:00:00
2018.01.01 10:00:00
2018.01.01 11:00:00
2018.01.02 01:00:00
2018.01.02 02:00:00
2018.01.02 03:00:00
2018.01.02 04:00:00
Col 2(Price-indexed)
55.09
44.02
44.0
33
43
43
33
33
我希望从数据中选择每天11:00的时间
我试过做一个序列,但在格林尼治标准时间的夏时制下,它在2019年和2020年10月变为12,这是不正确的
datos_2019_2020<-read.csv("DayaheadPricesfull_2019_2020.csv")
#price variable changed to numeric
datos_2019_2020$Price_indexed=as.numeric(datos_2019_2020$Price)
time_index_2019_2020 <- seq(from = as.POSIXct("2019-01-01 00:00"), to = as.POSIXct("2020-12-31 23:00"), by = "hour",tz="GMT")
eventdata_2019_2020 <- as.xts(datos_2019_2020$Price_indexed, drop = FALSE,order.by = time_index_2019_2020)
df.new_2019_2020 = eventdata_2019_2020[seq(12, nrow(eventdata_2019_2020), 24), ]
datos_2019_2020使用xts对象x
重复显示在末尾的注释中:
x[format(time(x), format = "%H:%M:%S") == "11:00:00"]
给定此xts对象:
[,1]
2018-01-01 11:00:00 NA
时区问题通常是特定于特定安装的,但问题通常是在当地时间和格林尼治标准时间之间,或由于标准时间和夏令时之间的切换。在这些情况下,通常最简单的方法是将整个会话设置为GMT
,使本地时间为GMT。在这种情况下,本地时间和GMT之间不会混淆,因为它们都是GMT,GMT没有夏令时
Sys.setenv(TZ = 'GMT')
注
line 1您可以在as.POSIXct
中添加tz='UTC'
,即time\u index\u 2019\u 2020
Lines1 <- "
2018.01.01 01:00:00
2018.01.01 02:00:00
2018.01.01 03:00:00
2018.01.01 04:00:00
2018.01.01 05:00:00
2018.01.01 06:00:00
2018.01.01 07:00:00
2018.01.01 08:00:00
2018.01.01 09:00:00
2018.01.01 10:00:00
2018.01.01 11:00:00
2018.01.02 01:00:00
2018.01.02 02:00:00
2018.01.02 03:00:00
2018.01.02 04:00:00"
Lines2 <- "
55.09
44.02
44.0
33
43
43
33
33"
library(xts)
col1 <- read.table(text = Lines1, sep = ",")
col2 <- read.table(text = Lines2)
# merge col1 and col2 using NA's to fill in
m <- merge(col1, col2, by = 0, all.x = TRUE)
z <- read.zoo(m[-1], tz = "", format = "%Y.%m.%d %H:%M:%S")
x <- as.xts(z)