【问题标题】:Set time series vectors lengths equal (resize/rescale them with use of linear interpolation)设置时间序列向量长度相等(使用线性插值调整它们的大小/重新缩放它们)
【发布时间】:2015-04-27 06:13:02
【问题描述】:

我有大量的时间序列数据集,它们表示为向量(没有可用的时间标签),由于测量过程中的一些错误,它们的长度(来自length() 显示的值)略有不同(~10%),但每个他们明确地描述了恰好两分钟的时间间隔。我想重新缩放/调整它们的大小,然后计算它们之间的一些统计数据(所以我需要等长的时间序列)。

我需要快速变化的方法,线性插值对我来说是非常好的选择,因为速度更重要。

简单示例,将长度为 5 的向量重新缩放为长度为 10 的向量:

input <- 0:4 # should be rescaled/resized into :
output <- c(0, .444, .888, 1.333, 1.777, 2.222, 2.666, 3.111, 3.555, 4)

我认为最快的方法是创建矩阵w('w'代表权重)维度是:length(output) x length(input),所以w %*% input gives output(as matrix object),如果是最快的方法,如何创建矩阵w有效吗?

【问题讨论】:

    标签: r datetime vector vectorization


    【解决方案1】:

    我认为这已经足够了:

    resize <- function (input, len) approx(seq_along(input), input, n = len)$y
    

    例如:

    > resize(0:4, 10)
     [1] 0.0000000 0.4444444 0.8888889 1.3333333 1.7777778 2.2222222 2.6666667 3.1111111 3.5555556 4.0000000
    
    > resize( c(0, 3, 2, 1), 10)
     [1] 0.000000 1.000000 2.000000 3.000000 2.666667 2.333333 2.000000 1.666667 1.333333 1.000000
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多