Matrices
In this page:
Matrices
A matrix is a two-dimensional collection of values of a single type, created with matrix(data, nrow, ncol). Elements are accessed with m[row, col], and an entire row or column can be selected by leaving the other index blank, like m[1, ]. Matrices support standard linear algebra operations like matrix multiplication with %*%.
Note: m[1, ] selects the entire first row; m[, 1] selects the entire first column.
Example: Matrices
m <- matrix(1:6, nrow = 2, ncol = 3)
print(m)
cat("Element at row 2, col 3:", m[2, 3], "\n")
print(m[1, ])
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: