A tidytensor t may have ranknames(t); this is a character vector of the same length as dim(t) for future use. Note that ranknames(t) is independent of names(t) or dimnames(t); we are not naming elements, or the dimension names for each rank, but rank names themselves. Like names() and dimnames(), unset ranknames() are NULL.

ranknames(x) <- value

Arguments

x

input tidytensor to set ranknames on.

value

what to store in ranknames(x).

Details

Ranknames for a tidytensor t are stored as the names() attribute of dimnames(t). If dimnames(t) happens to be null, before setting ranknames() we create valid dimnames() filled with NA values. The tidytensor package also provides a specialized dimnames() which preserves ranknames when setting dimnames().

See also

set_ranknames, dimnames<-

Examples

t <- as.tidytensor(array(1:(3 * 4 * 5), dim = c(3, 4, 5)))
ranknames(t) <- c("sample", "row", "col")
print(t)
#> # Rank 3 tensor, shape: (3, 4, 5), ranknames: sample, row, col
#> |  # Rank 2 tensor, shape: (4, 5)
#> |       1  13  25  37  49 
#> |       4  16  28  40  52 
#> |       7  19  31  43  55 
#> |      10  22  34  46  58 
#> |  # ...

# works like names():
t <- as.tidytensor(array(1:(3 * 4 * 5), dim = c(3, 4, 5)))
ranknames(t) <- c("sample", "row", "col")
print(ranknames(t))
#> [1] "sample" "row"    "col"   
ranknames(t)[3] <- "pixel"
print(t)
#> # Rank 3 tensor, shape: (3, 4, 5), ranknames: sample, row, pixel
#> |  # Rank 2 tensor, shape: (4, 5)
#> |       1  13  25  37  49 
#> |       4  16  28  40  52 
#> |       7  19  31  43  55 
#> |      10  22  34  46  58 
#> |  # ...