Arrays
In this page:
Arrays
An R array generalizes a matrix to more than two dimensions, storing data in a multi-dimensional grid with array(data, dim = c(...)). Elements are accessed by specifying an index for each dimension, like a[1, 2, 3]. Arrays are less commonly used than matrices or data frames but are useful for genuinely multi-dimensional data.
Note: A 2-dimensional array is functionally the same as a matrix -- matrix() is just a convenient special case.
Example: Arrays
arr <- array(1:24, dim = c(2, 3, 4))
cat("Dimensions:", dim(arr), "\n")
cat("Element at [1,2,3]:", arr[1, 2, 3], "\n")
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: