Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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]
share|improve this question
up vote 6 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

 
discard

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.