How to create a random matrix in r?

Ads
 

Ads

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

Ads









Related Tutorials/Questions & Answers:
How to create a random matrix in r?
how to create unit matrix in java of arbritary dimensions
Advertisements
How ro convert char into string??
How to Create Create Matrix of any order
Java create Identity matrix
generate random integer matrix in r
How ro convert char into string using recursive function in c#??
how to do actionsheet in iphone?-RV
how to do map in iphone?-RV
How to generate random number in java
how to do CRUDE operation in iphone?-RV
How to implement xml parsing in iphone ? -RV
How to generate a list of random numbers?
how to enter matrix data into a table of swings - Java Beginners
how to change file from .txt to .mat(matrix)
how to show random image in ASP.net?
Create array of random size
How do I generate random number?
Generating Random Number
how to make a matrix like datagrid in ide in java pls help
Version of com.conveyal>r5 dependency
Version of com.rongjih>rj-parent dependency
Selenium RC - Java Beginners
selenium rc java client driver - WebSevices
code java réseau de neurone
how to generate random questions - Java Beginners
matrix adddition
how to select random rows from database through servlet
how to find the eigenvalue and eigenvector of n*n matrix in java
How to create an input box?
How to create arrays in JavaScript?