# Removing elements of a table

I want removing elements of a table. For example, I have the next table:

data = {{0, 3}, {1, 3}, {2, 5}, {4, 2}, {5, 1}, {6, 8}, {7, 4}};


and I want removing all elements where the 1st element of sublist is between 6 and 2 for I obtain this new table:

data = {{0, 3}, {1, 3}, {6, 8}, {7, 4}};


The next code don´t work:

DeleteCases[data, Flatten[Select[data, 6 > #[[1]] > 2 &]]]


If only I want removing one element (for example {0,3}), the code work:

DeleteCases[data, Flatten[Select[data, 1 > #[[1]] >= 0 &]]]


How can I remove elements where the 1st element of sublist is between two values?.

• There has got to be a dupe for this, but in the meantime: why not stick to Select? E.g. Select[data, Not[6 > #[[1]] > 2] &]. – Marius Ladegård Meyer Aug 10 '16 at 9:46
• DeleteCases[data,x/;(x[[1]]>xmin&&x[[1]]<xmax)] where xmin and xmax are your thresholds for first element – Rom38 Aug 10 '16 at 9:47
• mathematica.stackexchange.com/q/2486/5478 – Kuba Aug 10 '16 at 9:54
• The second argument of DeleteCases must be a pattern. I recommend reading through some of these chapters: reference.wolfram.com/language/tutorial/PatternsOverview.html – Szabolcs Aug 10 '16 at 9:54
• Why {6,8} is left but {2,5} is not. – Kuba Aug 10 '16 at 9:55

You can pick the desired elements, e.g.

Pick[data, 2 <= #[[1]] < 6 & /@ data, False]
Pick[data, Not[2 <= #[[1]] < 6] & /@ data]


or deleting:

DeleteCases[data, {_?(2 <= # < 6 &), _}]

• When I import table of a file with two columns (x,y) I have data = {{{0, 3}, {1, 3}, {2, 5}, {4, 2}, {5, 1}, {6, 8}, {7, 4}}}. In these case only work the @MarkusDichtl code. I don´t understand why. – Manu Aug 10 '16 at 11:50
• @Manu I am sorry I do not understand your comment. In my timezone I am off to sleep. I will aim to look after I get up but I am certain other uses will resolve :) – ubpdqn Aug 10 '16 at 11:53
• @Manu. In that case, replace data in ubpdqn's code with First@data, and it should work. – march Aug 10 '16 at 16:03

New approach since v10.2:

data /. {x_ /; 6 > x >= 2, y_} -> Nothing


and Nothing just vanishes, resulting in

{{0, 3}, {1, 3}, {6, 8}, {7, 4}}

• In the version 10 work too. – Manu Aug 10 '16 at 11:22
• Nothing was introduced in 10.2, it's a special symbol for the standard evaluation process. – BoLe Aug 10 '16 at 11:35