Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 5 down vote accepted
list = {{1, 3}, {3, 7}};
insert[l_, max_] := Transpose[{Range[max], Normal[SparseArray[Rule @@@ l, max, Na]]}]
insert[list, 4]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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