OneBite.Dev - Coding blog in a bite size

shuffle the elements in an array in R

Code snippet on how to shuffle the elements in an array in R

  array_shuffled <- sample(array)

This code piece shuffles the elements in an array. The array is stored in a variable called “array”. Then a new variable called “array_shuffled” is created and its value is generated by calling a function called “sample()”, which randomly reorders the elements of the “array” variable. This will make the elements appear in a random order in the new array stored in the “array_shuffled” variable.

r