Here is a list of ten lists. Based on the second element alone some are unsuitable
In[]:=
test1={{"A",110468.,1978.,0.142501846},{"A",110512.,1978.,0.171648613},{"A",110540.,1978.,0.121514693},{"A",111721.,1978.,0.218872092},{"A",111722.,1978.,0.083322812},{"A",111725.,1978.,0.120864387},{"A",111728.,1978.,0.139541269},{"A",111916.,1978.,0.285463369},{"A",110468.,1979.,0.542969073},{"A",110512.,1979.,0.192196573}};​​TableForm[test1]​​Length[%]
Out[]//TableForm=
A
110468.
1978.
0.142502
A
110512.
1978.
0.171649
A
110540.
1978.
0.121515
A
111721.
1978.
0.218872
A
111722.
1978.
0.0833228
A
111725.
1978.
0.120864
A
111728.
1978.
0.139541
A
111916.
1978.
0.285463
A
110468.
1979.
0.542969
A
110512.
1979.
0.192197
Out[]=
10
Suppose I want to delete those with a particular value as the second element. It would seem this would do it...
In[]:=
DeleteCases[test1,#[[2]]==110468&]
Out[]=
{{A,110468.,1978.,0.142502},{A,110512.,1978.,0.171649},{A,110540.,1978.,0.121515},{A,111721.,1978.,0.218872},{A,111722.,1978.,0.0833228},{A,111725.,1978.,0.120864},{A,111728.,1978.,0.139541},{A,111916.,1978.,0.285463},{A,110468.,1979.,0.542969},{A,110512.,1979.,0.192197}}
But it doesn’t.
​
Once that problem is solved, I need to eliminate more than just a particular value. From the above list I wish to delete those which have, as their second element, any of certain values. We put these values to be deleted in a list named “forbid”
In[]:=
forbid={110468,110512};​​DeleteCases[test1,#[[2]]==#]&/@forbid
Part
:Part specification 110468〚2〛 is longer than depth of object.
Part
:Part specification 110512〚2〛 is longer than depth of object.
Out[]=
{{{A,110468.,1978.,0.142502},{A,110512.,1978.,0.171649},{A,110540.,1978.,0.121515},{A,111721.,1978.,0.218872},{A,111722.,1978.,0.0833228},{A,111725.,1978.,0.120864},{A,111728.,1978.,0.139541},{A,111916.,1978.,0.285463},{A,110468.,1979.,0.542969},{A,110512.,1979.,0.192197}},{{A,110468.,1978.,0.142502},{A,110512.,1978.,0.171649},{A,110540.,1978.,0.121515},{A,111721.,1978.,0.218872},{A,111722.,1978.,0.0833228},{A,111725.,1978.,0.120864},{A,111728.,1978.,0.139541},{A,111916.,1978.,0.285463},{A,110468.,1979.,0.542969},{A,110512.,1979.,0.192197}}}
I find it curious that this does work...
In[]:=
Select[test1,#[[2]]!=110468&]
Out[]=
{{A,110512.,1978.,0.171649},{A,110540.,1978.,0.121515},{A,111721.,1978.,0.218872},{A,111722.,1978.,0.0833228},{A,111725.,1978.,0.120864},{A,111728.,1978.,0.139541},{A,111916.,1978.,0.285463},{A,110512.,1979.,0.192197}}
...but this does not
In[]:=
Select[test1,#[[2]]!=110468∨#[[2]]!=110512&]
Out[]=
{{A,110468.,1978.,0.142502},{A,110512.,1978.,0.171649},{A,110540.,1978.,0.121515},{A,111721.,1978.,0.218872},{A,111722.,1978.,0.0833228},{A,111725.,1978.,0.120864},{A,111728.,1978.,0.139541},{A,111916.,1978.,0.285463},{A,110468.,1979.,0.542969},{A,110512.,1979.,0.192197}}
This works but is awkward. There must be an easier way...
In[]:=
Select[Select[test1,#[[2]]!=110468&],#[[2]]!=110512&]​​TableForm[%]
Out[]=
{{A,110540.,1978.,0.121515},{A,111721.,1978.,0.218872},{A,111722.,1978.,0.0833228},{A,111725.,1978.,0.120864},{A,111728.,1978.,0.139541},{A,111916.,1978.,0.285463}}
Out[]//TableForm=
A
110540.
1978.
0.121515
A
111721.
1978.
0.218872
A
111722.
1978.
0.0833228
A
111725.
1978.
0.120864
A
111728.
1978.
0.139541
A
111916.
1978.
0.285463
This works for a single record...
In[]:=
DeleteCases[test1,x_/;x[[2]]==110468];​​TableForm[%]​​
Out[]//TableForm=
A
110512.
1978.
0.171649
A
110540.
1978.
0.121515
A
111721.
1978.
0.218872
A
111722.
1978.
0.0833228
A
111725.
1978.
0.120864
A
111728.
1978.
0.139541
A
111916.
1978.
0.285463
A
110512.
1979.
0.192197
...but not for multiple
In[]:=
DeleteCases[test1,x_/;x[[2]]==#]&/@{110468,110512};​​TableForm[%]​​
Out[]//TableForm=
A
110512.
1978.
0.171649
A
110540.
1978.
0.121515
A
111721.
1978.
0.218872
A
111722.
1978.
0.0833228
A
111725.
1978.
0.120864
A
111728.
1978.
0.139541
A
111916.
1978.
0.285463
A
110512.
1979.
0.192197
A
110468.
1978.
0.142502
A
110540.
1978.
0.121515
A
111721.
1978.
0.218872
A
111722.
1978.
0.0833228
A
111725.
1978.
0.120864
A
111728.
1978.
0.139541
A
111916.
1978.
0.285463
A
110468.
1979.
0.542969
In[]:=
delFct[num_]:=Module[{},​​DeleteCases[test1,x_/;x[[2]]==num]​​];
In[]:=
delFct[#]&/@{110468,110512}
Out[]=
{{{A,110512.,1978.,0.171649},{A,110540.,1978.,0.121515},{A,111721.,1978.,0.218872},{A,111722.,1978.,0.0833228},{A,111725.,1978.,0.120864},{A,111728.,1978.,0.139541},{A,111916.,1978.,0.285463},{A,110512.,1979.,0.192197}},{{A,110468.,1978.,0.142502},{A,110540.,1978.,0.121515},{A,111721.,1978.,0.218872},{A,111722.,1978.,0.0833228},{A,111725.,1978.,0.120864},{A,111728.,1978.,0.139541},{A,111916.,1978.,0.285463},{A,110468.,1979.,0.542969}}}