Skip to contents

Shorthand to shuffle a list and save

Usage

list_shuffle(., seed = NULL)

Arguments

.

list to shuffle

seed

apply seed if indicated for reproducibility

Value

shuffled list of items store to the list name

Examples

list001 <- list("a" = 1:5,
           "b" = letters[1:5],
           c = LETTERS[1:10],
           "2" = number(5,5),
           "e" = randString(5,5))
list001 #show initial list
#> $a
#> [1] 1 2 3 4 5
#> 
#> $b
#> [1] "a" "b" "c" "d" "e"
#> 
#> $c
#>  [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
#> 
#> $`2`
#> [1] 28189 80214 53357 85890 20781
#> 
#> $e
#> [1] "opKJ4" "r116w" "gr5U1" "W4Ol0" "u120J"
#> 

#illustrate basic functionality
list_shuffle(list001)
list001 #shuffle and resaved to variable
#> $c
#>  [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
#> 
#> $b
#> [1] "a" "b" "c" "d" "e"
#> 
#> $a
#> [1] 1 2 3 4 5
#> 
#> $e
#> [1] "opKJ4" "r116w" "gr5U1" "W4Ol0" "u120J"
#> 
#> $`2`
#> [1] 28189 80214 53357 85890 20781
#> 

list.f2<-list001
list_shuffle(list.f2)
list.f2 #first output
#> $`2`
#> [1] 28189 80214 53357 85890 20781
#> 
#> $e
#> [1] "opKJ4" "r116w" "gr5U1" "W4Ol0" "u120J"
#> 
#> $c
#>  [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
#> 
#> $a
#> [1] 1 2 3 4 5
#> 
#> $b
#> [1] "a" "b" "c" "d" "e"
#> 

list.f2<-list001
list_shuffle(list.f2)
list.f2 # different output from first output top
#> $b
#> [1] "a" "b" "c" "d" "e"
#> 
#> $c
#>  [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
#> 
#> $a
#> [1] 1 2 3 4 5
#> 
#> $e
#> [1] "opKJ4" "r116w" "gr5U1" "W4Ol0" "u120J"
#> 
#> $`2`
#> [1] 28189 80214 53357 85890 20781
#> 

list.f2<-list001
list_shuffle(list.f2,seed = 344L)
list.f2 #second output
#> $a
#> [1] 1 2 3 4 5
#> 
#> $b
#> [1] "a" "b" "c" "d" "e"
#> 
#> $c
#>  [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
#> 
#> $e
#> [1] "opKJ4" "r116w" "gr5U1" "W4Ol0" "u120J"
#> 
#> $`2`
#> [1] 28189 80214 53357 85890 20781
#> 

list.f2<-list001
list_shuffle(list.f2,seed = 344L)
list.f2 #the same output as second output top
#> $a
#> [1] 1 2 3 4 5
#> 
#> $b
#> [1] "a" "b" "c" "d" "e"
#> 
#> $c
#>  [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
#> 
#> $e
#> [1] "opKJ4" "r116w" "gr5U1" "W4Ol0" "u120J"
#> 
#> $`2`
#> [1] 28189 80214 53357 85890 20781
#>