Possible Duplicate:
Select/Delete with Sublist elements?

I need help in filtering long lists of x,y coordinates.Lets use the following list as an example:


I need to filter out all the data points for which x<10. Therefore once the filtering is complete the new list should be:


Please help.Thank you!

  • 1
    $\begingroup$ Have a look at Select or Cases or DeleteCases. $\endgroup$ Dec 20, 2012 at 8:32
  • $\begingroup$ Possible duplicate: mathematica.stackexchange.com/q/2486/121 (I'll let others decide.) $\endgroup$
    – Mr.Wizard
    Dec 20, 2012 at 8:48
  • $\begingroup$ @Mr.Wizard I´d say no duplicate here but I have the feeling there is one out there (did not find it yet). $\endgroup$
    – Yves Klett
    Dec 20, 2012 at 8:57
  • $\begingroup$ @Yves anyone who reads and understands the answers to the linked question will immediately know how to solve this one. On that basis I think it is a duplicate. $\endgroup$
    – Mr.Wizard
    Dec 20, 2012 at 8:59
  • 1
    $\begingroup$ @Yves I just closed this based on Raghav's comment below. Please let me know if you find a more appropriate duplicate. If you disagree with the closure vote to re-open; I will not overrule that. $\endgroup$
    – Mr.Wizard
    Dec 20, 2012 at 9:22

1 Answer 1

 list = {{3, 5}, {7, 6}, {15, 6}, {23, 123}}

 DeleteCases[list, {x_, _} /; x < 10]
 DeleteCases[list, {_?(# < 10 &), _}]
 Cases[list, {x_, _} /; x >= 10]
 Cases[list, {_?(# >= 10 &), _}]
 Select[list, First[#] >= 10 &]
 Pick[list, First[#] >= 10 & /@ list]
 list /. {x_, _} /; x < 10 :> Sequence[]
 list /. {_?(# < 10 &), _} :> Sequence[]
 (* {{15, 6}, {23, 123}} *)
  • 2
    $\begingroup$ kguler, I'm certain this question is a duplicate. Please consider applying your effort to find the original, rather than posting an answer. Of course if you are unable to find the original (even if you know it's out there somewhere) go ahead and answer. $\endgroup$
    – Mr.Wizard
    Dec 20, 2012 at 8:37
  • $\begingroup$ The "duplicate" I found is linked above. I posted my own answer, and voted for yours, as I suppose it could be argued that it is not a duplicate. Nevertheless I think it is, but I didn't want to cast a binding vote. $\endgroup$
    – Mr.Wizard
    Dec 20, 2012 at 8:52
  • 1
    $\begingroup$ Mr.W I too was certain that we have seen this question before, and did spend more time to search than to type the answer:), But to my surprise, in my search with the keywords Cases, Select, Pick the Q/A's I found were all related to more complex cases than this one or had some "more advanced" elements. Somehow, I missed the Q/A you linked to. $\endgroup$
    – kglr
    Dec 20, 2012 at 9:05
  • 1
    $\begingroup$ Thank you for your help! I tried searching for similar posts but I could not find one. @Mr.Wizard I saw your link and understood how to solve my own problem so thank you for that. $\endgroup$
    – Raghav
    Dec 20, 2012 at 9:15
  • 1
    $\begingroup$ @Raghav welcome to Mathematica.SE. You're welcome. Based on your recognition that the answer to the linked question were sufficient for you to solve your problem I am going to close your question as a duplicate. Please do not look upon this as anything other than a housekeeping measure, which it is. Thank you for trying to find a similar question before posting one of your own; I know that is often not easy (Google sometimes helps). $\endgroup$
    – Mr.Wizard
    Dec 20, 2012 at 9:20

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