Friday, 23 August 2013

R - shuffle a list preserving element sizes

R - shuffle a list preserving element sizes

In R, I need an efficient solution to shuffle the elements contained
within a list, preserving the total number of elements, and the local
element sizes (in this case, each element of the list is a vector)
a<-LETTERS[1:6]
b<-LETTERS[6:10]
c<-LETTERS[c(9:15)]
l=list(a,b,c)
> l
[[1]]
[1] "A" "B" "C" "D" "E" "F"
[[2]]
[1] "F" "G" "H" "I" "J"
[[3]]
[1] "I" "J" "K" "L" "M" "N" "O"
The shuffling shoul randomly select the elements of the list (without
replacement) and recreate a list with the same element sizes. I hope I
have been clear! Thanks :-)

No comments:

Post a Comment