How can the missing time series values be filled?

5

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?

CA Trevillian

Posted 2020-06-05T14:09:03.293

Reputation: 2 817

Answers

7

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}} *)
```

flinty

Posted 2020-06-05T14:09:03.293

Reputation: 14 405

6btw, TimeSeriesResample[tslistmissingvalues] gives the same result (+1). – kglr – 2020-06-05T14:35:39.610