Maybe you just need approx
? E.g., approx(some.series, n=length.max.series)
. This function offers constant or linear interpolation.
Stretching multiple time series in R
-
28-09-2022 - |
Вопрос
I have a csv, with the columns representing a set of measurements taken over a period of time (in this case, the opening area of a larynx during a breath).
However, the times series (may) different numbers of measurements. eg:
23,34,44
25,35,39
23,33,,
23,,,
Using ts.plot(data)
I've been able to plot these on the same graph. However, I need each series to be "stretched" to the same length. (Such that each column in the CSV represents the same distance on the x-axis, but with varying resolution) How might this be best achieved?
Additionally, I had been using lines(rowMeans(data, na.rm = TRUE))
to produce an average, which I also need to do with the "stretched" series.
I had been considering performing the interpolation (up to some arbitrary resolution such at 1000) in Ruby, and then producing a new CSV file to run the original R code against. I would expect there, however, to be a more elegant solution in R.
Решение