dim-names: Dimension names

Description Usage Arguments Details Value Examples

Description

This family of functions allows you to get and set dimension names in various ways.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

Arguments

x

The object to extract the dimension names for.

value

For rray_dim_names<-(), a list containing either character vectors or NULL corresponding to the new dimension names to use for x. Otherwise, identical to names.

dim_names

A list of either character vectors or NULL representing the new dim names of x. If NULL is supplied, the dim names of x are removed.

axis

A single integer. The axis to select dimension names for.

names

A character vector of new dimension names for the axis dimension. This is also allowed to be NULL to remove dimension names for the specified axis.

meta

A single character representing an optional "meta" name assigned to the axis names. If NULL, the current meta name is kept.

Details

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.

Value

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.

Examples

 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
x <- rray(1:10, c(5, 2))
rray_dim_names(x) <- list(letters[1:5], NULL)
x
rray_dim_names(x)

# 3D object, so 3 dim name elements
rray_dim_names(rray(1, dim = c(1, 1, 1)))

# Vectors are treated as 1D arrays
vec <- c(x = 1, y = 2)
rray_dim_names(vec)

# 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

# You can set also set axis names to `NULL` to reset them
rray_set_axis_names(y, 2, NULL)

# You can set the "meta" names of an axis as well
rray_set_axis_names(y, 1, "r1", "row names")

rray documentation built on July 23, 2019, 5:04 p.m.