Manipulating Vectors and Matrices
How to manipulate vectors and matrices in Julia and R? The following table translates the most common Julia commands into R language.
Julia  R  

Transpose  
A.' 
t(A) 

Complex conjugate transpose  
A ' 
Conj(t(A)) 

Concatenate horizontally  
A = [[1 2] [1 2]] 
A = c(c(1,2),c(1,2)) 

Concatenate vertically 

A = [[1 2]; [1 2]] 
A = rbind(c(1,2),c(1,2)) 

Reshape (to 5 rows, 2 columns) 

A = reshape(1:10, 5, 2) 
A = matrix(1:10,5,2) 

Convert matrix to vector 

A[:] 
c(A) 

Repeat matrix (3 times in the row dimension, 4 times in the column dimension) 

repmat(A,3,4) 
kronecker(matrix(1,3,4),A) 

Flip Matrix form left to right 

flipdim(A, 2) 
A[,dim(A)[2]:1] 

Flip Matrix up/down 

flipdim(A, 2) 
A[dim(A)[1]:1,] 
Complete JuliaR Cheatsheet
1) Creating Vectors
2) Creating Matrices
3) Creating Random Numbers
4) Manipulating Vectors and Matrices
5) Accessing Vector/Matrix Elements
Advertisements
5 thoughts on “JuliaR Cheatsheet – Manipulating Vectors and Matrices”