Description Usage Arguments Details Value See Also Examples
A functional form of e.g. tensor[1:10, 3, ]
, supporting selecting by ranknames, usage with
indexing when the rank is unknown.
1 2 |
x |
the tidytensor to apply over. |
... |
named or unnamed parameters specifying subsetting criteria (see examples) |
drop |
whether to drop ranks with size 1 (similar to |
Subsetting a tidytensor with subset()
as opposed to []
allows for subsetting even when the number of ranks of the input is unknown; see examples.
a tidytensor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # shape [100, 26, 26, 3]
t <- as.tidytensor(array(rnorm(100 * 26 * 26 * 3), dim = c(100, 26, 26, 3)))
ranknames(t) <- c("sample", "row", "col", "channel")
t <- set_dimnames_for_rank(t, channel, R, G, B)
print(t)
t2 <- subset(t, row = 1:10, sample = 27, drop = FALSE)
print(t2)
# same thing, but without named ranks (not a good idea to mixes named
# subsetting and non-named subsetting)
t2 <- subset(t, 27, 1:10, drop = FALSE)
print(t2)
# equiv of t3[1:20, , , c("G", "R", "B")] # since the last rank has dimnames()
# note the re-ordering of channel levels
t3 <- subset(t, sample = 1:20, channel = c("G", "R", "B"), drop = FALSE)
print(t3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.