mercredi 29 janvier 2020

Randomize letters in pairs (R)

I have a task in my statistics class that reads: Write an R function that randomly configures the plugboard. This function will take no input but will randomly select a set of 13 pairs of letters. The output object should be a 2 x 13 matrix for which each column represents a pair of letters. You may use the built-in R object letters, which contains the 26 letters of the alphabet as a character vector. Name the function plugboard.

I have tried to use: matrix(sample(letters),2,13), which creates the 2 x 13 matrix, and randomizes the 13 pairs of letters every time I run it. But when I create:

plugboard <- matrix(sample(letters),2,13),

and then try to type plugboard a few times, it shows the letters in the same order every time. Can anyone please explain to me how to do this correctly?

Thanks :)




Aucun commentaire:

Enregistrer un commentaire