Julia-R Cheatsheet – Creating Matrices

Creating Matrices

How to create matrices in Julia and R? The following table translates the most common Julia commands into R language.

Julia R
Create a matrix
 
A = [1 2; 3 4]
 
A = matrix(c(1,2,3,4),2,2)
Create a 2 x 2 matrix of zeros
 
A = zeros(2,2)
 
A = matrix(0,2,2)
Create a 2 x 2 matrix of ones
 
A = ones(2,2)
 
A = matrix(1,2,2)
Create a 2 x 2 identity matrix
 
A = eye(2,2)
 
A = diag(2)
Create a diagonal matrix
 
A = diagm([1;2;3;])
 
A = diag(c(1,2,3))

Complete Julia-R Cheatsheet
1) Creating Vectors
2) Creating Matrices
3) Creating Random Numbers
4) Manipulating Vectors and Matrices
5) Accessing Vector/Matrix Elements

 

Advertisement

5 thoughts on “Julia-R Cheatsheet – Creating Matrices”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.