Extract with [
on a specified dimension
extract_dim(X, which_dim, idx, drop = NULL, depth = Inf) extract_rows(X, idx, drop = NULL, depth = Inf) extract_cols(X, idx, drop = NULL, depth = Inf)
X | Typically, an array, but any object with a |
---|---|
which_dim | A scalar integer or character, specifying the dimension to extract from |
idx | A numeric, boolean, or character vector to perform subsetting with. |
drop | Passed on to |
depth | Scalar number, how many levels to recurse down if |
# extract_rows is useful to keep the same code path for arrays of various sizes X <- array(1:8, c(4, 3, 2)) y <- c("a", "b", "c", "d") (Y <- onehot(y))#> a b c d #> [1,] 1 0 0 0 #> [2,] 0 1 0 0 #> [3,] 0 0 1 0 #> [4,] 0 0 0 1extract_rows(X, 2)#> [,1] [,2] #> [1,] 2 6 #> [2,] 6 2 #> [3,] 2 6extract_rows(Y, 2)#> a b c d #> 0 1 0 0extract_rows(y, 2)#> [1] "b"#> [,1] [,2] #> [1,] 2 6 #> [2,] 6 2 #> [3,] 2 6Y2#> a b c d #> 0 1 0 0y2#> [1] "b"