R检查分离的时间序列表的一致性

时间:2015-10-30 17:28:25

标签: r

我有一个像这样的时间表 - 一直到2000 31 12 23(12/31/2000 23:00):

timeseries-format

我想将几个天气的温度值添加到它。问题是,显然不同的时间序列不能按行数匹配,因此必须有间隙。

如果这些数据框符合0-24小时,1-12个月的模式并获取这些差距的信息,我该如何查看这些数据框?

2 个答案:

答案 0 :(得分:0)

如果您的数据采用链接格式,则可以通过执行以下操作将其转换为POSIXct对象(假设您的数据框称为数据):

temp = as.data.frame(list(YY = rep("1962",10),
                      MM = rep("01",10),
                      DD = rep("01",10),
                      HH = c("00","01","02","03","04",
                             "05","06","07","08","09")))

date1 = paste(temp$YY,temp$MM,temp$DD,sep="-")

temp$dateTime = as.POSIXct(paste(date1,temp$HH,sep=" "),format="%Y-%m-%d %H")

temp$temp = round(rnorm(10,0,5),1)
temp = temp[,c("dateTime","temp")]

#let's say your temperature dataset is missing an entry for a certain timestamp
temp = temp[-3,]

# this data frame won't have an entry for 02:00:00
data1 = merge(data,temp)
data1

# if you want to look at time differences you can try something like this
diff(data1$dateTime)

# this one will fill in the temp value as NA at 02:00:00
data2 = merge(data,temp,all.x = T)
data2

diff(data2$dateTime)

这应该将您的数据放入POSIXct格式。如果您的温度数据集还有一个名为" dateTime"它是一个POSIXct对象,你应该能够使用合并功能,它将结合两个数据框

{{1}}

我希望有帮助,我经常在尝试匹配生态数据集的时间戳时使用合并功能

答案 1 :(得分:0)

感谢您的回答,对不起我迟到的回复。 虽然我现在设法以稍微不同的方式合并我的所有时间序列,但无法在没有您的帮助提示的情况下制作它:

Sys.setenv(TZ='UTC') #setting system time to UTC for not having DST-gaps

# creating empty hourly timeseries for following join
start = strptime("1962010100", format="%Y%m%d%H")
end = strptime("2000123123", format= "%Y%m%d%H")
series62_00 <- data.frame(
MESS_DATUM=seq(start, end, by="hour",tz ='UTC'), t = NA)

# joining all the temperatureseries with same timespan using "plyr"-package
library("plyr")
t_allstations <- list(series62_00,t282,t867,t1270,t2261,t2503
,t2597,t3668,t3946,t4752,t5397,t5419,t5705)
t_omain_DWD <- join_all(t_allstations, by = "MESS_DATUM", type = "left")

join_alltype = "left"一起使用可确保该列&#34;日期&#34;没有更改,缺少的温度值填入NA's