How to create a random matrix in r?

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

View Answers

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









Related Tutorials/Questions & Answers:
How to create a random matrix in r?
how to create unit matrix in java of arbritary dimensions
Advertisements
How to Create Create Matrix of any order
generate random integer matrix in r
Java create Identity matrix
How ro convert char into string??
ModuleNotFoundError: No module named 'rk'
ModuleNotFoundError: No module named 'r3'
ModuleNotFoundError: No module named 'R4'
ModuleNotFoundError: No module named 'rr'
ModuleNotFoundError: No module named 'rn'
How ro convert char into string using recursive function in c#??
ModuleNotFoundError: No module named 'rg_pynester'
ModuleNotFoundError: No module named 'rg_pynester'
ModuleNotFoundError: No module named 'rp'
ModuleNotFoundError: No module named 'voice-assistant-RK'
ModuleNotFoundError: No module named 'rh-doozer'
ModuleNotFoundError: No module named 'rh-elliott'
ModuleNotFoundError: No module named 'rh-util'
ModuleNotFoundError: No module named 'rb'
How to generate random number in java
ModuleNotFoundError: No module named 'RO'
ModuleNotFoundError: No module named 'rr-cilantro'
ModuleNotFoundError: No module named 'rr-fmk'
ModuleNotFoundError: No module named 'rg-python-utils'
ModuleNotFoundError: No module named 'rg-python-utils'
ModuleNotFoundError: No module named 'rj_nester'
how to do actionsheet in iphone?-RV
how to do map in iphone?-RV
Maven dependency for com.rongjih - rj-parent version 0.1.0 is released. Learn to use rj-parent version 0.1.0 in Maven based Java projects
ModuleNotFoundError: No module named 'rp_arith'
ModuleNotFoundError: No module named 'rp_nester'
ModuleNotFoundError: No module named 'webauthn-rp'
ModuleNotFoundError: No module named 'rm'
ModuleNotFoundError: No module named 'rm'
ModuleNotFoundError: No module named 'rr-aws-glue-libs'
ModuleNotFoundError: No module named 'rw'
ModuleNotFoundError: No module named 'rw'
ModuleNotFoundError: No module named 'rw'
ModuleNotFoundError: No module named 'ru'
ModuleNotFoundError: No module named 'li-rn-networks'
ModuleNotFoundError: No module named 'zk-rn-lib-maker'
ModuleNotFoundError: No module named 'rb_oauth'
ModuleNotFoundError: No module named 'rbpy-rb'
ModuleNotFoundError: No module named 'rb-tree'
ModuleNotFoundError: No module named 'sampleworld-rb'
ModuleNotFoundError: No module named 'ro-manager'
r4 data science
ModuleNotFoundError: No module named 'rf'
ModuleNotFoundError: No module named 'robotframework-rp-tools'

Ads