[R] Vectors, Loops, Rnorm and KS-Testing

Dylan Keenan dylan.keenan at gmail.com
Mon May 23 16:32:10 CEST 2016

Use 'replicate.'

> replicate(n1, mean(rnorm(n2, mean, sd)))

Will compute return a column vector of length n1, each entry of which is
the mean of n2 random normal variables with mean and sd specified by the
arguments of rnorm.

On Mon, May 23, 2016 at 10:25 AM Nicoletta Sabov <nicoletta.sabov at hotmail.de>

> Hi there,
> I need a function, that calculates the mean of a desired amount of
> normally distributed numbers and repeats this process for a desired number
> of repetitions. The function should return only a single vector consisting
> solely of the calculated means. Also the user of this function must be able
> to specify the parameters of the normal distribution used while calculating
> the means. I need this function for the Kolmogorov Smirnov Test.
> I am a total beginner, so far I only have come to this point:
> kolmo <- function(x, mean, sd, rep){
>   for(i in rep){
>     cat(mean(rnorm(x, mean, sd)))
> }}
> This returns a simple number, but I do need a vector to be returned.
> Thanks a lot in advance!
>         [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

	[[alternative HTML version deleted]]

More information about the R-help mailing list