Reputation: 19
lapply(rep(list(sample(1:100)), 10), sort, partial = 1:10)
... is what I'm trying to do. But the partial = 1:10 term is only evaluated once. What is the simplest method to evaluate the list of ten sample(1:100)'s with ten i++-style values passed to partial?
I apologize for being inarticulate.
A follow-up question is whether there is a more efficient method of generating these samples. What might this look like in a single custom function?
Thank you.
Upvotes: 2
Views: 116
Reputation: 28632
To answer your original question: you can use the multivariate version of sapply
/lapply
, eg
mapply(sort, x = list(sample(1:100, 10)), partial = 1:10)
If you want to return a list
, set SIMPLIFY
to FALSE
.
Upvotes: 1