Create i.i.d. Normal Random Variables in Matrix in R (Example Code)

In this R tutorial you’ll learn how to create a matrix or data frame consisting of i.i.d. normal random columns.

Example: Creating Random Matrix with i.i.d. Normal Distributions

set.seed(198573)                                 # Random seed for reproducibility
random_matrix <- matrix(rnorm(50), nrow = 10)    # Generate random matrix
random_matrix                                    # Display random matrix
#              [,1]        [,2]        [,3]         [,4]       [,5]
#  [1,] -2.10955643 -0.32423950  0.68660311 -0.730127136 -1.5883473
#  [2,]  1.16512885 -0.54150120  2.75273347 -1.588989291 -0.8745217
#  [3,] -0.03452589 -0.10858146  0.08361507  0.348810756 -0.2889596
#  [4,] -1.01420940 -0.12942312 -0.76362881 -1.508036241  0.3000911
#  [5,]  1.19975744 -0.89124489 -0.55403006 -2.264796052  0.7074794
#  [6,] -0.32805990 -1.22171296 -0.21520247 -0.201566943  0.9100003
#  [7,] -1.19915320 -1.17513184  0.25305045  0.826637569 -0.9904934
#  [8,] -0.86593514  0.66906715  0.01643435 -0.154540034  1.1357078
#  [9,]  0.46729470 -0.24310666 -1.15224666 -2.896349773  0.6721109
# [10,]  0.55232914 -0.04685203  0.97621677 -0.009069976  0.1277064

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top