Message Boards Message Boards

0
|
9116 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:
GROUPS:

Pattern matching - how to match on a number greater than or less than X

Posted 11 years ago
In the example list belowe how should I construct the pattern matching to remove any item where position 4 is greater than 20000?

listX = {{m,b,24,14000},{f,b,29,14000},{m,w,72,67000},{m,b,45,84000},{m,w,67,17000},{f,w,54,4000}};

I thought it would be something like DeleteCases[listX,{_,_,_,x_>20000}] but that doesn't work.  Does pattern matching only work on exact matches only?

Thanks for your help - greatly appreciated!
POSTED BY: Tim Heger
2 Replies
Try:
DeleteCases[listX, {_, _, _, x_} /; x > 20000]
I think you have to match the pattern, then test it.
POSTED BY: C ormullion
Posted 11 years ago
Worked perfectly!

Thanks for your help!
POSTED BY: Tim Heger
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract