Find missing values in time series and fill them with Na

2

I have this list

list = {{1, 3}, {3, 7}};

representing a time series from t = 1 to t = 4.

How would I go about filling the missing values so that my list looks like this in the end:

list = {{1, 3}, {2,Na}, {3, 7}, {4,Na}};

Of course, the length of my list and position of missing values might vary so I need a general function to do this, not just

Insert[list,{2,Na},2]

Sulli

Posted 2014-02-28T12:36:42.753

Reputation: 2 025

Answers

6

list = {{1, 3}, {3, 7}};
insert[l_, max_] := Transpose[{Range[max], Normal[SparseArray[Rule @@@ l, max, Na]]}]
insert[list, 4]

Coolwater

Posted 2014-02-28T12:36:42.753

Reputation: 17 733