插值随着时间的推移

时间:2016-12-08 11:06:06

标签: r time-series interpolation

在数据框中,我有一天四次测量的风速数据,分别是00:00,06:00,12:00和18:00。为了将这些与其他数据结合起来,我需要在15分钟的分辨率之间填补时间。我想通过简单的插值填补空白。

以下示例生成两个对应的示例数据帧。需要合并df1df2。在得到的合并数据帧中,6小时值(其中var == NA?)之间的间隙值需要通过简单均值插值来填充。 我的问题是如何合并两者并在给定值之间进行具体插值。

第一个数据框

创作:

# create a corresponding sample data frame
df1 <- data.frame(
  date = seq.POSIXt(
    from = ISOdatetime(2015,10,1,0,0,0, tz = "GMT"),
    to = ISOdatetime(2015,10,14,23,59,0, tz= "GMT"),
    by = "6 hour"
  ),
  windspeed = abs(rnorm(14*4, 10, 4)) # abs() because windspeed shoud be positive
)

生成的数据框:

> # show the head of the dataframe
> head(df1)
                 date windspeed
1 2015-10-01 00:00:00 17.928217
2 2015-10-01 06:00:00 11.306025
3 2015-10-01 12:00:00  6.648131
4 2015-10-01 18:00:00 10.320146
5 2015-10-02 00:00:00  2.138559
6 2015-10-02 06:00:00  9.076344

第二个数据框

创作:

# create a 2nd corresponding sample data frame
df2 <- data.frame(
  date = seq.POSIXt(
    from = ISOdatetime(2015,10,1,0,0,0, tz = "GMT"),
    to = ISOdatetime(2015,10,14,23,59,0, tz= "GMT"),
    by = "15 min"
  ),
  var = abs(rnorm(14*24*4, 300, 100))
)

生成的数据框:

> # show the head of the 2nd dataframe
> head(df2)
                 date      var
1 2015-10-01 00:00:00 198.2657
2 2015-10-01 00:15:00 472.9041
3 2015-10-01 00:30:00 605.8776
4 2015-10-01 00:45:00 429.0949
5 2015-10-01 01:00:00 400.2390
6 2015-10-01 01:15:00 317.1503

0 个答案:

没有答案