# Matrix
## Definition(s)
### Nexus: [[Nexus - Google Analytics Certificate Course]]
#### Topic: [[Google Analytics - 7 Data Analysis with R Programming - Module 2 - Programming using RStudio]]
>[! Definition]
>A two-dimensional collection of data elements with rows and columns
## Examples
```r
# R program to create a matrix
A = matrix(
# Taking sequence of elements
c(1, 2, 3, 4, 5, 6, 7, 8, 9),
# No of rows
nrow = 3,
# No of columns
ncol = 3,
# By default matrices are in column-wise order
# So this parameter decides how to arrange the matrix
byrow = TRUE
)
# Naming rows
rownames(A) = c("a", "b", "c")
# Naming columns
colnames(A) = c("c", "d", "e")
cat("The 3x3 matrix:\n")
print(A)
```
```output
The 3x3 matrix:
c d e
a 1 2 3
b 4 5 6
c 7 8 9
```
Credit: [Geekforgeeks.com explainer doc](https://www.geeksforgeeks.org/r-matrices/)
## Related
[[Vector]]
[[Data Structure]]
## Resources
[Geekforgeeks.com explainer doc](https://www.geeksforgeeks.org/r-matrices/)
## Flashcards
The below code are generated for use with [Spaced Repetition plugin](https://github.com/st3v3nmw/obsidian-spaced-repetition/) [docs](https://www.stephenmwangi.com/obsidian-spaced-repetition/)