Selecting elements of a list based on frequency
Here's an example:
counts = l // Flatten // Counts;
mask = Map[counts[#] != 1 &, l, {2}];
Pick[l, mask]
{{"a", "b", "c"}, {"a", "b"}, {"a", "b"}, {"a", "c"}}
And for the other one,
mask = Map[counts[#] > 1 &, l, {2}];
Pick[l, And @@@ mask]
{{"a", "b", "c"}, {"a", "b"}}
Another way:
Map[
If[counts[#] != 1, #, Nothing] &,
l, {2}]
{{"a", "b", "c"}, {"a", "b"}, {"a", "b"}, {"a", "c"}}
If[And @@ (counts[#] > 1 & /@ #), #, Nothing] & /@ l
{{"a", "b", "c"}, {"a", "b"}}
Alternatives using Select
rather than Pick
:
l = {{"a", "b", "c"}, {"a", "b"}, {"a", "d", "b"}, {"a", "c", "e"}};
counts = Counts[Flatten@l];
To obtain the sublists whose elements are repeated in the list:
Select[ContainsNone[Keys@Select[# == 1 &]@counts]@l (* Out: {{"a", "b", "c"}, {"a", "b"}} *)
To remove those sublists that contain non-repeated elements in the overall list:
DeleteCases[Alternatives @@ Keys@Select[# == 1 &]@counts] /@ l (* Out: {{"a", "b", "c"}, {"a", "b"}, {"a", "b"}, {"a", "c"}} *)