Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

randperm

Random Permutation


Description

Generates a random permutation.

Usage

randperm(a, k)

Arguments

a

integer or numeric vector of some length n.

k

integer, smaller as a or length(a).

Details

Generates one random permutation of k of the elements a, if a is a vector, or of 1:a if a is a single integer.

Value

Vector of permuted elements of a or 1:a.

Note

This behavior is different from Matlab/Octave, but does better correspond with the behavior of the perms() function.

See Also

Examples

randperm(1:6, 3)
randperm(6, 6)
randperm(11:20, 5)
randperm(seq(2, 10, by=2))

pracma

Practical Numerical Math Functions

v2.3.3
GPL (>= 3)
Authors
Hans W. Borchers [aut, cre]
Initial release
2021-01-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.