rray_extract() is the counterpart to rray_yank(). It extracts elements
from an array by index. It always drops dimensions
(unlike rray_subset()), and a 1D object is always returned.
rray_extract(x, ...) <- value rray_extract_assign(x, ..., value) rray_extract(x, ...)
| x | A vector, matrix, array, or rray. |
|---|---|
| ... | A specification of indices to extract.
|
| value | The value to assign to the location specified by |
A 1D vector of elements extracted from x.
Like [[, rray_extract() will never keep dimension names.
rray_extract() works with base R objects as well.
rray_extract() is similar to the traditional behavior of
x[[i, j, ...]], but allows each subscript to have length >1.
Other rray subsetters: rray_slice<-,
rray_subset<-, rray_yank<-
x <- rray(1:16, c(2, 4, 2), dim_names = list(c("r1", "r2"), NULL, NULL)) # Extract the first row and flatten it rray_extract(x, 1)#> [1] 1 3 5 7 9 11 13 15# Extract the first row and first two columns rray_extract(x, 1, 1:2)#> [1] 1 3 9 11# You can assign directly to these elements rray_extract(x, 1, 1:2) <- NA x#> <rray<int>[,4,2][2]> #> , , 1 #> #> [,1] [,2] [,3] [,4] #> r1 NA NA 5 7 #> r2 2 4 6 8 #> #> , , 2 #> #> [,1] [,2] [,3] [,4] #> r1 NA NA 13 15 #> r2 10 12 14 16 #>