Using DeleteCases with a defined function with two arguments as a pattern

I am trying to manipulate some large datasets in Mathematica. I have plotted the data, and I would like to be able to easily remove points from the dataset, and it's fairly easy to identify the x-values of the points I need to remove. Let's say I need to remove the data point at an x-value of 1.1. To do this, I could do something like this:

BadData[entry_] := MatchQ[entry, {1.1, _?NumberQ}]


However, I have 6 other data sets, all of which I have to remove different outliers (not at 1.1). I'd like to define a function such as

BadData[entry_, bad_] := MatchQ[entry, {bad, _?NumberQ}]


because then for bad I can just put whatever the x-value is of the point I need to remove. I tested the function out by figuring out that the data point with 1.1 as the x-value is the 7th in data, and running

BadData[data[[7]], 1.1]


returns True. So I know the function works the way I want it to, even though I know this might not be the "prettiest" way to do this.

What I can't figure out is how to use this version of baddata as a pattern in DeleteCases because I don't know how to specify the second variable, which would be 1.1 for this set. Is this possible with the setup I have currently?

• Try this: DeleteCases[data, _?(BadData[#, 1.1] &)] – Anjan Kumar May 1 at 4:41

You can use an implicit function more explicitly, as

data = {{1, 5}, {1.1, 6}, {2, 7}};


{{1, 5}, {2, 7}}

You can also define BadData as a pure function:

BadData[bad_] := First[#] == bad&


Then:

DeleteCases[data, _?(BadData[1.1])]


{{1, 5}, {2, 7}}

Another possibility is:

BadData[bad_] := EqualTo[bad] @* First