# NOT RUN {
x <- rray(10:17, c(2, 2, 2))
# Resulting dimension is always 1D
rray_yank(x, 1:3)
# With logical
rray_yank(x, FALSE)
rray_yank(x, rep(c(TRUE, FALSE), times = rray_elems(x) / 2))
# You can assign a 1D vector to these yanked selections
rray_yank(x, c(1, 3, 5)) <- 9
# Logicals with the same dim as `x`
# can also be used as a yank indexer
lgl <- rray(c(TRUE, FALSE), c(2, 2, 2))
rray_yank(x, lgl)
# And you can set elements in these locations
rray_yank(x, lgl) <- NA
# `[[` for rray objects is powered by
# rray_yank().
# This can be very useful for
# performing assignment
# by position.
x[[c(1, 3)]] <- NA
# Logical arrays with the same shape as `x`
# can be assigned to. This is a useful way
# to get rid of NA values.
idx <- array(is.na(as.vector(x)), c(2, 2, 2))
x[[idx]] <- 0
# }
Run the code above in your browser using DataLab