This family of functions allows you to get and set dimension names in various ways.
rray_dim_names() returns a list of the dimension names.
rray_axis_names() returns a character vector or NULL containing the
names corresponding to the axis dimension.
rray_row_names() and rray_col_names() are helpers for getting the
row and column names respectively.
Each of these four functions also has "set" variants: a functional form
(i.e. rray_set_row_names()), and an assignment
form (i.e. rray_row_names<-()).
rray_dim_names(x) rray_dim_names(x) <- value rray_set_dim_names(x, dim_names) rray_axis_names(x, axis) rray_axis_names(x, axis) <- value rray_set_axis_names(x, axis, names, meta = NULL) rray_row_names(x) rray_row_names(x) <- value rray_set_row_names(x, names, meta = NULL) rray_col_names(x) rray_col_names(x) <- value rray_set_col_names(x, names, meta = NULL)
| x | The object to extract the dimension names for. |
|---|---|
| value | For |
| dim_names | A list of either character vectors or |
| axis | A single integer. The axis to select dimension names for. |
| names | A character vector of new dimension names
for the |
| meta | A single character representing an optional "meta" name
assigned to the |
rray_dim_names() returns a list of dimension names. The other names
functions return character vectors, or NULL, corresponding to the
names of a particular axis.
Unlike dimnames() which can return NULL, rray_dim_names() always returns a
list the same length as the dimensionality of x. If any dimensions do not
have names, NULL is returned for that element of the list. This
results in an object that's length always matches the dimensionality of x.
#> <rray<int>[,2][5]> #> [,1] [,2] #> a 1 6 #> b 2 7 #> c 3 8 #> d 4 9 #> e 5 10rray_dim_names(x)#> [[1]] #> [1] "a" "b" "c" "d" "e" #> #> [[2]] #> NULL #>#> [[1]] #> NULL #> #> [[2]] #> NULL #> #> [[3]] #> NULL #>#> [[1]] #> [1] "x" "y" #># You can add dim names more easily # using rray_set_axis_names() # and the pipe operator library(magrittr) y <- rray(1, c(1, 2, 1)) %>% rray_set_axis_names(1, "r1") %>% rray_set_axis_names(2, c("c1", "c2")) %>% rray_set_axis_names(3, "3rd dim") y#> <rray<dbl>[,2,1][1]> #> , , 3rd dim #> #> c1 c2 #> r1 1 1 #># You can set also set axis names to `NULL` to reset them rray_set_axis_names(y, 2, NULL)#> <rray<dbl>[,2,1][1]> #> , , 3rd dim #> #> [,1] [,2] #> r1 1 1 #># You can set the "meta" names of an axis as well rray_set_axis_names(y, 1, "r1", "row names")#> <rray<dbl>[,2,1][1]> #> , , = 3rd dim #> #> #> row names c1 c2 #> r1 1 1 #>