5
$\begingroup$

Though there appears to be a similar question, it does not sate this use-case...

I present below the MWE: I have a date-list, here it is just a linear series of numbers, but the real use-case is that they are months, or days, etc. (They’re months) Each time-value corresponds to a discrete count, which does not change until, well, it changes—so normal interpolations make it seem...off.

tslistmissingvalues={{1,1},{3,2},{5,3},{6,4},{11,5},{14,6},{16,7},{18,8}};

How can the missing values be filled such that the end result is as such:

tslistmissingvaluesfilled={{1,1},{2,1},{3,2},{4,2},{5,3},{6,4},{7,4},{8,4},{9,4},{10,4},{11,5},{12,5},{13,5},{14,6},{15,6},{16,7},{17,7},{18,8},{19,8},{20,8}};

How can the missing values be filled in this time series of discrete counts?

$\endgroup$

1 Answer 1

7
$\begingroup$
tslistmissingvalues = {{1, 1}, {3, 2}, {5, 3}, {6, 4}, {11, 5}, {14, 
    6}, {16, 7}, {18, 8}};
TimeSeriesResample[tslistmissingvalues, 
 ResamplingMethod -> {"Interpolation", InterpolationOrder -> 0}]

(* output: {{1, 1}, {2, 1}, {3, 2}, {4, 2}, {5, 3}, {6, 4}, {7, 4}, {8, 4}, {9, 
  4}, {10, 4}, {11, 5}, {12, 5}, {13, 5}, {14, 6}, {15, 6}, {16, 
  7}, {17, 7}, {18, 8}} *)
```
$\endgroup$
1
  • 6
    $\begingroup$ btw, TimeSeriesResample[tslistmissingvalues] gives the same result (+1). $\endgroup$
    – kglr
    Commented Jun 5, 2020 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.