Learn R Programming

fgpt (version 2.3)

fyshuffle: Fisher-Yates shuffle

Description

Function to shuffle vectors according to the Fisher-Yates procedure

Usage

fyshuffle(x)

Arguments

x
Vector containing the sequence which needs to be shuffled. This vector can be of any type and it is allowed to have one element.

Value

A randomized version of the input vector.

Details

Other than the sample function fyshuffle treats a single value as a vector with one element and will therefore return this element as the shuffled version of the original vector (which are similar).

References

Durstenfeld (1964) Communications of the ACM 7(7):420

See Also

sample

Examples

Run this code
x <- 1:10
fyshuffle(x)

y <- c("a","b","c","d","e","f")
fyshuffle(y)

Run the code above in your browser using DataLab