Nick Ellis offered an efficient solution to my previous question (copied
below).
Try, e.g.,
do.call("rbind",sample(grip,3,replace=T))
do.call() is very handy when you have a variable list or arguments to a
function. sample() seems to be able to take a list as its argument, even
though the documentation doesn't say so.
original question
Say I have a list (grip) composed of 5 matrices (grip1, grip2, grip3,
grip4, grip5). Each matrix gives coordinates x and y (rows and columns)
which will later be used to fill in a larger matrix, z.grip. For my
algorithm, I would like to randomly sample 1 or more (n) of the matrices
from the list and return their coordinates as a single matrix or directly
assign a value to the z.grip matrix by the output of the randomly sampled
matrix of coordinates. Furthermore I would like to perform this operation
in 1 step, if possible.
|