# How do I remove particular $x$ and $y$ values from a list of data points?

I have data points of the form {x,y,z}:

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


And I need to remove entire data points based on a condition. For example, let's say that I want to remove any data points where z > 6. The result should be this:

s2 = {{0, 1, 2}, {3, 4, 5}}


How do I do this? I think DeleteCases might be the way to go, but I'm still fairly inexperienced with Mathematica and am not sure how to use this function to make this work.

s = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
s2 = Pick[s, Thread[s[[All, 3]] > 6], False]


or

s2 = Pick[s, Thread[s[[All, 3]] <= 6]]


{{0, 1, 2}, {3, 4, 5}}

• Can this be used to set upper and lower bounds for a coordinate in one go? Commented Nov 8, 2017 at 21:41
• @whatwhatwhat You can write Thread[4 <= s[[All, 3]] <= 6] Commented Nov 8, 2017 at 21:55
• @what, you might also be interested in the function Between[]. Commented Nov 9, 2017 at 0:15

DeleteCases works perfectly here, although I think Select is a bit more natural

DeleteCases[s, {_, _, _?(# > 6 &)}]
Select[s, Last@# <= 6 &]

(* {{0, 1, 2}, {3, 4, 5}} *)
(* {{0, 1, 2}, {3, 4, 5}} *)