Let's say I imported a large list of numbers into Mathematica, and found the min value and max value. In that range [min,max], how do I find all integers that do not appear in this list?

data = Flatten[Import["file.txt", "Table"]];
M = Max[data]
m = Min[data]


newdata = DeleteDuplicates [data];

I get this:

The range of values are

{19,20,22,..., 126, 128}

So I can tell that 21, for example, is missing

  • $\begingroup$ I'm totally missing your logic here. How exactly can a list have elements larger than its maximum? $\endgroup$ – J. M.'s ennui Apr 11 '18 at 5:13
  • $\begingroup$ I apologize, I specifically put the range, I'm trying to figure out how to put an output that specifically takes values that are missing in the range $\endgroup$ – mastud89 Apr 11 '18 at 5:38
  • 1
    $\begingroup$ To clarify: you want to get the members of Range[Max[data]] that are not present in data? Have you seen Complement[]? $\endgroup$ – J. M.'s ennui Apr 11 '18 at 5:46
  • $\begingroup$ I've heard of it, but I forgot what it was used for. I search on it in Wolfram and it's a pretty basic tool to find what is missing in a range of values. $\endgroup$ – mastud89 Apr 11 '18 at 5:56
Complement[Range[m, M], data]

(*   {21, 24, 121, 124, 125, 127}   *)
  • 2
    $\begingroup$ Also: Complement[Range @@ MinMax[data], data] $\endgroup$ – J. M.'s ennui Apr 11 '18 at 5:52

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