[R] Multivariate Normal and loops

R. Michael Weylandt michael.weylandt at gmail.com
Fri Jun 15 17:34:05 CEST 2012


I don't think you need loops at all actually :-) [The main thing to
working with R vs. C is "vectorization" -- embrace it now and life
will be much better]

You could do something like this:

library(MASS) # Provides a multivariate normal distribution

mvrnorm(100, c(1,5), matrix(c(2,1,1,2), ncol = 2))

This gives you 100 samples of a multivariate normal with mean vector
(1,5) and covariance matrix

(2, 1,
 1, 2)

Feel free to tweak as necessary and type ?mvrnorm to see more documentation.

Hopefully this gets you started.

For more on vectorization, see the "Introduction to R" that comes with
R. You can get it by typing help.start() at your command prompt.

Hope this helps,
Michael

On Fri, Jun 15, 2012 at 9:26 AM, Cassie <letamotta at hotmail.com> wrote:
> Hi,
> i'm not english and i'm not very familiar to R, and i'm asking if you can
> help me.
> I'm wondering how to create a multivariate normal an then repeat this for a
> sample of T=1000, and the save this result.
> Thank you very much for your helping
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Multivariate-Normal-and-loops-tp4633504.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list