I have a list of element pairs:
pairList = {{1,2}, {2, 3}, {3, 4}, {4, 5}};
I'd list to pick a subset of the elements in this list:
pairListSubset = {2, 5};
Now, wherever any pairListSubset element occurs, I'd like to replace it with an element sampled without replacement from list in replacementSets occurring at the same index position in pairListSubset. Extending the previous example:
replacementSets = {{"a", "b", "c"}, {"d", "e", "f"}};
With the example provided the result of this procedure may result in one of the following nine possibilities:
pairListFinal = ...
{{1,"a"}, {"b", 3}, {3, 4}, {4, "d"}}
{{1,"a"}, {"c", 3}, {3, 4}, {4, "d"}}
{{1,"b"}, {"c", 3}, {3, 4}, {4, "d"}}
{{1,"a"}, {"b", 3}, {3, 4}, {4, "e"}}
{{1,"a"}, {"c", 3}, {3, 4}, {4, "e"}}
{{1,"b"}, {"c", 3}, {3, 4}, {4, "e"}}
{{1,"a"}, {"b", 3}, {3, 4}, {4, "f"}}
{{1,"a"}, {"c", 3}, {3, 4}, {4, "f"}}
{{1,"b"}, {"c", 3}, {3, 4}, {4, "f"}}
How can I concisely carry out this list operation? To simplify things, it would be fine to pick the first element of each replacementSets list, then the second element, and so on. Its not important to sample randomly without replacement.
GroupBy). If you are using an earlier version please let me know and I shall provide an alternative. – Mr.Wizard Jan 04 '15 at 10:58