Extracts a subset from an array. You can also use the [ operator.
Supports R-style indexing including scalar indices (which drop dimensions),
ranges (a:b), and array(c(...)) for selecting multiple elements along a
dimension.
Arguments
- x
(
arrayish)
Same asoperand; this is the name used by the base R S3 generic.- ...
Subset specifications, one per dimension. Omitted trailing dimensions select all elements. See
vignette("subsetting")for details.- operand
(
arrayish)
Operand.
See also
nv_subset_assign() for updating subsets, vignette("subsetting")
for a comprehensive guide.
Examples
x <- nv_matrix(1:12, nrow = 3)
x
#> AnvlArray
#> 1 4 7 10
#> 2 5 8 11
#> 3 6 9 12
#> [ CPUi32{3,4} ]
# Select row 2
x[2, ]
#> AnvlArray
#> 2
#> 5
#> 8
#> 11
#> [ CPUi32{4} ]
# Select rows 1 to 2, all columns
x[1:2, ]
#> AnvlArray
#> 1 4 7 10
#> 2 5 8 11
#> [ CPUi32{2,4} ]