[R] shuffling a vector

Peter J. Acklam pjacklam at online.no
Mon Nov 10 18:29:58 CET 2003


rxg218 at psu.edu wrote:

> I'me trying to write  a function that will shuffle a vector.
> At the moment I'm baically making a vector of randomized indices
> and then making  a new vector from the original one using these
> random indices.

What's your definition of "elegant"?  :-)

Isn't this elegant enough?

   x[order(runif(length(x)))]

Peter

-- 
Peter J. Acklam - pjacklam at online.no - http://home.online.no/~pjacklam




More information about the R-help mailing list