Accessing Vector/Matrix Elements
How to access vector and matrix elements in Julia and R? The following table translates the most common Julia commands into R language.
| Julia | R | |
|---|---|---|
| Access one element | ||
A[2, 2] |
A[2, 2] |
|
| Access specific rows | ||
A[1:4, :] |
A[1:4,] |
|
| Access specific columns | ||
A[:, 1:4] |
A[,1:4] |
|
| Concatenate vertically |
||
A = [[1 2]; [1 2]] |
A = rbind(c(1,2),c(1,2)) |
|
| Remove a row |
||
A[[1, 2, 4], ] |
A[-3, ] |
|
| Diagonals of matrix |
||
diag(A) |
diag(A) |
|
| Get dimensions of matrix |
||
size(A) |
dim(A) |
|
Complete Julia-R Cheatsheet
1) Creating Vectors
2) Creating Matrices
3) Creating Random Numbers
4) Manipulating Vectors and Matrices
5) Accessing Vector/Matrix Elements
5 thoughts on “Julia-R Cheatsheet – Accessing Vector/Matrix Elements”