On Jun 22, 2010, at 7:15 AM, sta...@quo.org wrote:
Hi Barbara,
You could use:
samples = matrix(rep(0,(5000*40)),ncol=40)
for(i in 1:5000) {
samples[i,] = sample(1:40,40)
}
Might also be a good time to use replicate():
samples = matrix(replicate(5000, sample(1:40) ), ncol=40, byrow=TRUE)
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.
And by default the number of sampled is length of the sampled vector,
so it returns a permutation.
The "for" loop is generally slower than using "lapply",
Can you cite any evidence for that assertion?
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
--
David Winsemius, MD
West Hartford, CT
______________________________________________
R-help@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.