我有两个不同时间间隔的数据帧:第一个是每3个小时;第二个是每15分钟一次。我想写一个'for'循环,就像这样
for(time in levels(15mins interval), e.g. (00:00,00:15,00:30,...){
if(time is between 3h interval, e.g. 00:15 is between 00:00 and 03:00){
regress 00:15 data onto 00:00 and 03:00 data
}else{regress 00:00 data in 2nd data frame onto 00:00 data in 1st data frame}
我不知道如何实现这一点。有没有办法比较时间? 提前谢谢。
答案 0 :(得分:0)
df_time=data.frame(cbind(index=1:96, time=levels(df1$time)))
for(ind in 1:96){
if(ind %% 12 ==1){
do something with df_time[ind,2]
}else{
tim1=df_time[ind %/% 12 +1 , 2]
tim2=df_time[ind %/% 12 +13, 2]
do something with tim1 & tim2
}}