I am pretty weak on the notion of pure functions, etc. I found a clean solution to my problem so in a sense I've already answered my own question but I don't feel I'm on terra firma.
I wanted to take a random sample from a list of lists with a different sample size for each list in the list of lists. I did the following which is clean and readable by the cognoscenti. I'll probably have trouble understanding this in a year. Comments and/or suggestions of better ways will be appreciated.
listoflists = {{1, 2, 3, 4}, {5, 6, 7}, {8, 9}, {10, 11, 12, 13}};
samplesizes = {2, 3, 1, 3};
out=Apply[RandomSample, Transpose[{listoflists, samplesizes}], {1}]
Apply
at level 1" asRandomSample @@@ Transpose[{listoflists, samplesizes}]
. I find this more readable because I don't have to scan to the end of the expression to find the{1}
part. It might not be easier to remember what it does in a year's time though. I do in fact use this frequently when theTranspose[{listoflists, samplesizes}]
part is already constructed and stored somewhere. $\endgroup$RandomSample[#, #2] & @@@
is longer but maybe one will find it better. OrTable[RandomSample[listoflists[[i]], samplesizes[[i]]], {i, 4}]
$\endgroup$