Alternate implementation from the docs for sample(): resample <- function(x, ...) x[sample.int(length(x), ...)]