Description Usage Value Examples
pad()
is used alongside the standard rray subsetting operator [
(and
the underlying rray_subset()
function) to easily subset into higher
dimensions without having to explicitly list the intermediate commas.
1 | pad()
|
An object that can be used to pad dimensions with when subsetting.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | x <- rray(1:4, c(1, 1, 2, 2))
# pad() fills in the missing dimensions
# essentially it adds commas automatically
# second element in the 4th dimension
x[pad(), 2]
# vs using
x[,,,2]
# second element in 3rd
# first element in 4th
x[pad(), 2, 1]
# can fill in the missing gaps too
# this fills in the 2nd/3rd dimensions
x[1, pad(), 1]
# if a pad() isn't needed
# because the dimensionality is already fully
# specified by the indices, its ignored
x_flat <- rray_reshape(x, 4)
x_flat[pad(), 1]
x_flat[1, pad()]
# `pad()` can be used with base R
# objects as well through `rray_subset()`
x_arr <- as.array(x)
rray_subset(x_arr, pad(), 1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.