Suppose I have a list,
list = Table[{n}, {n, 1, 5}]
(* list = {{1},{2},{3},{4},{5}} *)
and I want to remove all values from this list that are greater than 3, so that I get
newlist = {{1}, {2}, {3}}
Is there a way to do this without having something cumbersome like
newlist1 = list /. {4} -> Sequence[]
(* newlist1 = {{1}, {2}, {3}, {5}} *)
newlist = newlist1 /. {5} -> Sequence[]
(* newlist = {{1}, {2}, {3}} *)
possibly with an If statement?
Some context: I have a set of circles and a list of each circle's radius, but I want to remove all the circles with radius $r$ outside of a few set ranges. For example, if I have a hundred circles with radii ranging from 1 to 10, I would then like to eliminate all the circles with radii $r<2$, those with $4<r<6$, and those with $r>8$.
Any suggestions are appreciated.
Edit: Here's what I've tried by adapting Nasser's code:
rad = {34.6302, 10.0623, 6.94622, 26.3059, 52.6308,
27.1662, ... , 80.0562, 799.3, 44.5997, 14.0357}
DeleteCases[rad, {x_} /; {x>10 And x<700}]
(* the 799.3 is an extreme outlier *)
but I apparently don't understand the syntax required for setting multiple constraints. I've tried different variations, like
DeleteCases[rad, {x_,y_} /; {x>3, y<1}]
but again, no luck.
DeleteCases[list, x_ /; First@x > 3]
If you had made your table like this:Table[n, {n, 1, 5}]
it would be easier a little:DeleteCases[list, x_ /; x > 3]
$\endgroup$/. 4->Sequence[]
didn't work properly. $\endgroup$DeleteCases[rad, x_ /; (x > 10 && x < 700)]
then it will work. I get{6.94622, 799.3}
$\endgroup$DeleteCases[rad, x_ /; (First@x > 10 && First@x < 700)]
You needFirst@
to be dox[[1]]
basically, since eachx
is a list now. (you can writex[[1]]
if you prefer. $\endgroup$