If the goal is to "look" professional, then 'replicate' probably suits. If the goal is to compute as fast as possible, then that isn't the case because 'replicate' is really a 'for' loop in disguise and there are other ways.
Here's one other way:
function (size, replicates, distfun, ...)
{
colMeans(array(distfun(size * replicates, ...), c(size,
replicates)))
} Patrick Burns [email protected] +44 (0)20 8525 0696 http://www.burns-stat.com (home of "The R Inferno" and "A Guide for the Unwilling S User") Uwe Ligges wrote:
megh wrote:No, it is not homework. I obviouslyFor some value of "obvious" as you has not given a single line of code as the posting guide suggests.You probably want: replicate(10, mean(rnorm(100))) Uwe Liggescould do that using a for-loop, and thatI already did. However I thought whether there could be a better approach asit was looking very messy and unprofessional. Uwe Ligges-3 wrote:megh wrote:Hi, I am trying to create a vector of length 10 (say), wherein each element will be average of random sample of size 100, from a distribution, say Normal. Can anyone please tell me without creating a "for" loop, how I can do that?Homework? Then please ask you course material or teacher. PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Uwe LiggesRegards,______________________________________________ [email protected] 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.______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
______________________________________________ [email protected] 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.

