0
$\begingroup$

I have this list:IndividualsPossible

ind = 40;
StrategiesCop = {{"1", "c", "d", "r", "r"}, {"1", "c", "d", "nr", 
"r"}, {"1", "d", "d", "r", "r"}, {"1", "d", "d", "nr", "r"}, {"2",
 "d", "c", "r", "r"}, {"2", "d", "c", "r", "nr"}, {"2", "d", "d", 
"r", "r"}, {"2", "d", "d", "r", "nr"}};
IndividualsPossible = 
Table[{RandomChoice[{"1", "2"}], RandomChoice[{"c", "d"}], 
RandomChoice[{"c", "d"}], RandomChoice[{"r", "nr"}], 
RandomChoice[{"r", "nr"}]}, {i, 1, 4*ind}];

and I need to delete some elements that I don´t need from all possible combinations

{"1", "c", "d", "nr", "nr"}, {"1", "c", "d", "r", "nr"}, {"1", "d", \
"d", "nr", "nr"}, {"1", "d", "d", "r", "nr"}, {"2", "d", "c", "r", \
"r"}, {"2", "d", "c", "r", "nr"}, {"2", "d", "d", "r", "r"}, {"2", \
"d", "d", "r", "nr"}

I tried with DeleteCases but this delete one each time.

$\endgroup$
1
  • 2
    $\begingroup$ You gave examples of what you want removed, yet you didn't say the criterion satisfied by the elements you want to remove. $\endgroup$ Mar 15, 2018 at 4:42

1 Answer 1

0
$\begingroup$
lst = {{"1", "c", "d", "r", "r"}, {"1", "c", "d", "nr", "r"}, {"1", "d", "d", "r", "r"}, 
  {"1", "d", "d", "nr", "r"}, {"2", "d", "c",  "r", "r"}, {"2", "d", "c", "r", "nr"}, 
  {"2", "d", "d", "r",  "r"}, {"2", "d", "d", "r", "nr"}};
del = {{"2", "d", "c", "r", "nr"}, {"2", "d", "d", "r", "r"}, {"2", "d", "d", "r", "nr"}};

DeleteCases[lst, Alternatives @@ del]

{{"1", "c", "d", "r", "r"}, {"1", "c", "d", "nr", "r"}, {"1", "d", "d", "r", "r"}, {"1", "d", "d", "nr", "r"}, {"2", "d", "c", "r", "r"}}

Or

Complement[lst, del]

{{"1", "c", "d", "nr", "r"}, {"1", "c", "d", "r", "r"}, {"1", "d", "d", "nr", "r"}, {"1", "d", "d", "r", "r"}, {"2", "d", "c", "r", "r"}}

Or

lst /. Alternatives @@ del -> Sequence[]

{{"1", "c", "d", "r", "r"}, {"1", "c", "d", "nr", "r"}, {"1", "d", "d", "r", "r"}, {"1", "d", "d", "nr", "r"}, {"2", "d", "c", "r", "r"}}

$\endgroup$
2
  • $\begingroup$ If I don´t want to create manually the del list, what can I do? $\endgroup$
    – Ask8
    Mar 15, 2018 at 5:18
  • $\begingroup$ @Lina, then, as mentioned by J.M., you need to specify the " criterion satisfied by the elements you want to remove". $\endgroup$
    – kglr
    Mar 15, 2018 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.