Re: [R] random sequence

From: <status_at_quo.org>
Date: Tue, 22 Jun 2010 06:15:22 -0500

Hi Barbara,

You could use:

samples = matrix(rep(0,(5000*40)),ncol=40) for(i in 1:5000) {

    samples[i,] = sample(1:40,40)
}

This will give you a matrix of samples, one per row. The second term in the "sample" function is the length of your sequence. By default "sample" samples without replacement, so there won't be any duplicates.

The "for" loop is generally slower than using "lapply", but for just 5000 samples it won't make much difference.

Cheers,

Matt Asher
StatisticsBlog.com

> I have a sequence of number from 1 to 40 and I have to extract a random
> sequence, for example:
> 1) 1, 2 3, 4, ...40
> 2) 2, 10, 9 , 25....
>
> e so on for 5000 times. How I can do????
> Thanks
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 22 Jun 2010 - 11:18:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Jun 2010 - 14:00:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive