See ?replicate, e.g. replicate(sum(sample(1:6,100,replace=TRUE)), n=10)
Function arguments are (in gneral) evaluated as if they were evaluated when passed to the function. On Mon, 8 Oct 2007, Zembower, Kevin wrote: > I'm trying to get R to simulate the sum of the values on 10 fair dice > (yes, it's related to a homework problem, but is not the problem > itself). I tried to do this: >> rep(sum(sample(1:6,100,replace=T)), times=10) > [1] 341 341 341 341 341 341 341 341 341 341 > > and noticed that sum(sample()) seems to be only evaluated once. How can > I overcome this, so that I get a vector of values that correspond to > independent throws of 10 dice each time? > Kevin Zembower > Internet Services Group manager > Center for Communication Programs > Bloomberg School of Public Health > Johns Hopkins University -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ 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.