Wednesday, November 7, 2012

Generate random permutation in R

Generate random permutation in R

start = 1
end = 10
seq = c(start, end)
sample(seq,length(seq), replace=FALSE)

Equivalent MathLab: X = randperm(End-Begin+1)+Begin

example: [1]  5  1  2  8  6  4  3  7  9 10

No comments:

Post a Comment