[R] shuffling a vector

Marc Schwartz MSchwartz at medanalytics.com
Mon Nov 10 17:51:42 CET 2003


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'
package.

Example:

> x <- 1:10
> permute(x)
 [1]  1  3  2  6  5  7 10  8  9  4

HTH,

Marc Schwartz




More information about the R-help mailing list