samedi 23 décembre 2017

Producing a random sequence of number... 30 times

Happy holidays! I have a question that I haven’t been able to figure out.

I need to produce a set of integers (from 1 to 20) of random length, and this needs be reproduced 30 times. To generate the random-length list, I use the “runif” function, which works. However, when I use the “rep” function to repeat this random list, it simply repeats the same list 30 times. What I want is the following: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 etc.

Insted, the runif produces a list and rep repeats it 30 times, so it looks like this: 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 etc.

I’d ideally like R to run the “runif” command 30 times. Now, I don’t know how to write a loop for this, and I also don’t know how to use something more elegant than loops. I tried using “repeat” function, but that one doesn’t produce integers, but lists which I cannot use for the computation I need.

Any help/advice/ideas would be greatly appreciated!

Thank you.




Aucun commentaire:

Enregistrer un commentaire