I'm trying to select elements of a list that satisfy some criteria using Manipulate[]
.
Given 2 lists:
list1 = {{a, b, c}, {d, e, f}, {g, h, i}};
list2 = {{9, 0}, {2, 1}, {9.5, 3}};
I want to build a function that, when some criteria are True
, will look for them at a specific position in list2
. Let me show with an example:
Consider the case in which I only want to find if elements in position 1 of list2
are >=9
and then take the corresponding position from list1
. I would write
Pick[list1, Map[#[[1]] >= 9 &, list2]]
(*{{a, b, c}, {g, h, i}}*)
However, if I was to look into elements in position 1 being >=9
and elements of position 2 being <2
I would write
Pick[list1, Map[#[[1]] >= 9 && #[[2]] < 2 &, list2]]
(*{{a, b, c}}*)
But what I want is to have a manipulable function that uses the And
function in the second case, but without excluding the possibility that only one of the criterion may be desired. I.e., when only c1 = True
I want the first case to be analyzed; when only c2 = True
I only want the second case; when both are true, I want the both conditions to be analyzed.
I was thinking about using the following function, but this doesn't work mainly because the new list is not even created.
Manipulate[
Block[{conditional, condlist, c1, c2},
condlist = {};
If[c1, Insert[condlist, #[[1]] > 9, -1]];
If[c2, Insert[condlist, #[[2]] > 3, -1]];
condlist
(*Pick[list1, Map[condlist &, list2]]*)
], {c1, {True, False}}, {c2, {True, False}}]
Anyone has any tips on how I can solve this? Thanks in advance!
Edit: though the example I present here only considers 2 conditionals c1
and c2
, this is to be applied to a much larger set of conditions. It includes 8 conditionals, and may have any combination among it (e.g. c1 AND c2 AND c4
, or c7
, or c5 AND c6 AND c7
, etc).