The unlist(res) would throw all the different columns into one list to sample from. I distinctly wanted them to be distinct samples so I can see an example of what sort of data items are in each field meeting my criteria. If I'm going to use an anonymous function, then it defeats the purpose. I'd just wrap sample myself. What I would need to do is take each element of res and unlist it to make it a vector. Then it would feed into sample just fine. This would be avoided if I could run sqlQuery (RODBC) and return a single field as a vector. I could have tweaked it or pre-processed res so that each item was converted to a vector before running lapply. However, I wanted to work with what I had, so
There's also the advantage to this that the return object is itself not a vector, which may be an advantage in this case: table-in to table-out.
I must have misread your solution. The lapply(lapply(res, unlist), sample, 5) would be an appropriate (and more efficient) approach. It's just embedding the pre-processing required to supply a vector input.
Code:
Vectorize(sample)(data.frame(A = letters), 5)
I must have misread your solution. The lapply(lapply(res, unlist), sample, 5) would be an appropriate (and more efficient) approach. It's just embedding the pre-processing required to supply a vector input.