# How to create a random matrix in r?

Hi,

I want to create random matrix in R programming language. How to create a random matrix in r?

Explain me with the good example code.

Thanks

July 15, 2017 at 9:40 AM

Hi,

In R Programming language random numbers can be generated with the help of function `rnorm(n, mean = , sd = )`.

Here is the example code of generating ram matrix with rnorm() function:

```> r <- replicate(5, rnorm(20))
> r
[,1]        [,2]        [,3]        [,4]        [,5]
[1,] -0.1012611 -0.52069878  0.34236854 -0.16282334  2.47735262
[2,]  0.9029532  0.28693232 -1.74086296 -0.33426393  2.34203830
[3,]  1.2858879 -0.03309967 -1.14784979 -1.28360246 -0.29461179
[4,]  0.6997275  0.39133528  0.21690133  1.94755917 -1.04784043
[5,] -1.6416680 -0.23461394  0.13961023  0.55696923 -0.09267539
[6,]  0.1355967 -0.93748646  0.77509980  1.28715050 -0.21332211
[7,]  0.3926482 -0.03526129  1.31058294  0.39913134 -0.19821495
[8,]  0.3679493  0.04213181  0.43288016 -1.68080332 -0.20521307
[9,] -0.4021257 -0.31609840  0.82748026  1.23177211 -0.68174512
[10,]  0.4512571 -0.06498939  1.92221985 -0.48335945  2.00781344
[11,]  2.9192589 -0.62850207 -0.26687069 -1.75451658  1.20647529
[12,] -0.7050517  0.41514636  0.40638555 -1.19671481 -0.54820705
[13,] -1.2236033  0.93309134 -1.39043336  0.90584500  0.48886437
[14,]  0.4826153  2.02422493  0.37830880  1.13595205  1.33587131
[15,]  1.6722725 -1.35776628  0.98359688 -0.29253937  0.13695947
[16,] -0.9941718 -2.04867588 -0.41936767 -1.30736261 -1.34375375
[17,] -0.3759544 -0.02773437  0.06730548 -0.08617226 -1.19938600
[18,] -0.6064091  0.07646071 -0.35426011  1.05810632  0.41599185
[19,] -1.1719113 -1.30699768  0.37224764  1.69884737  0.61336575
[20,] -0.3935953  0.80802704  0.26697530 -1.41631026 -0.32860454
>
```

Are you looking for R Programming Tutorials? Check our R Programming Tutorials sections and learn R programming.

Thanks