[R] shuffling a vector
MSchwartz at medanalytics.com
Mon Nov 10 17:57:17 CET 2003
On Mon, 2003-11-10 at 10:51, Marc Schwartz wrote:
> On Mon, 2003-11-10 at 10:28, Rajarshi Guha wrote:
> > Hi,
> > 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.
> > However, is there an alternative (more elegant) method to do this? I
> > tried help.search('shuffle') but it does'nt return anything relevant.
> > Thanks,
> You might want to look at the permute() function in the 'gregmisc'
> > x <- 1:10
> > permute(x)
>  1 3 2 6 5 7 10 8 9 4
> Marc Schwartz
A quick add:
Also the sample() function in the base package:
 4 10 5 3 7 2 1 6 9 8
See ?sample for more information. sample() is also more flexible in
terms of options if you want more than just a permutation of the
More information about the R-help