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
  • 2,185
  • 14
  • 28

1 Answers1

6
list = {{1, 3}, {3, 7}};
insert[l_, max_] := Transpose[{Range[max], Normal[SparseArray[Rule @@@ l, max, Na]]}]
insert[list, 4]
Coolwater
  • 20,257
  • 3
  • 35
  • 64