Am 27.09.2008 um 05:46 schrieb John Sorkin:
Windows XP
R 2.7.1
I am trying to use apply (or lapply, sapply) to get the sample
function to select 1000 samples of size 10 from c(1,2,3) with
probability c(0.1,0.2,0.7), i.e.
for (i in 1:1000)
{
j<-sample(c(1,2,3),10,replace=TRUE,prob=c(0.1,0.2,0.7))
print(j)
}
matrix(sample(c(1, 2, 3), 10000, replace=TRUE, prob=c(.1, .2, .7)),
nrow=10)
or
replicate(sample(c(1, 2, 3), 10, replace=TRUE, prob=c(.1, .2, .7)),
1000)
______________________________________________
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.