R检查分离的timeseries表的一致性

R检查分离的timeseries表的一致性,r,R,我有一个这样的timeseries表,它一直到2000 31 12 23(12/31/2000 23:00): 我想加上几个气象站的温度值。问题是,很明显,不同的时间序列在行数上不匹配,因此肯定存在间隙 如果这些数据帧因此遵循0-24小时、1-12个月的模式,我如何检查这些数据帧,并获取这些差距在哪里的信息?如果您的数据是链接格式的,则您可能可以通过执行以下操作将其转换为POSIXct对象(假设您的数据帧称为数据): 这会将数据转换为POSIXct格式。如果您的温度数据集也有一个名为“date

我有一个这样的timeseries表,它一直到2000 31 12 23(12/31/2000 23:00):

我想加上几个气象站的温度值。问题是,很明显,不同的时间序列在行数上不匹配,因此肯定存在间隙


如果这些数据帧因此遵循0-24小时、1-12个月的模式,我如何检查这些数据帧,并获取这些差距在哪里的信息?

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

这会将数据转换为POSIXct格式。如果您的温度数据集也有一个名为“dateTime”的列,并且它是一个POSIXct对象,那么您应该能够使用merge函数,它将组合两个数据帧

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)

我希望这能有所帮助,当我试图从生态数据集中匹配时间戳时,我经常使用merge函数

谢谢你的回答,很抱歉我的回复太晚了。 如果没有您的帮助提示,我将无法完成此任务,尽管我现在以稍微不同的方式合并了我的所有timeseries:

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")
Sys.setenv(TZ='UTC')#将系统时间设置为UTC,以避免出现DST间隙
#为以下联接创建空的小时时间序列
start=strtime(“1962010100”,格式=“%Y%m%d%H”)
end=strtime(“2000123123”,格式=“%Y%m%d%H”)
系列62_00
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")