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:
list={{3,5},{7,6},{15,6},{23,123}}
I need to filter out all the data points for which x<10
. Therefore once the filtering is complete the new list should be:
newlist={{15,6},{23,123}}
Please help.Thank you!
Answer
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}} *)
Comments
Post a Comment