dimlabels<- {str2str}R Documentation

Add Elements to Vectors

Description

`dimlabels<-` adds elements to vectors as a side effect. The purpose of the function is to replace names(dimnames(x)) with a single function call.

Usage

dimlabels(x) <- value

Arguments

x

array or any object with dimnames. The object may or may not already have dimlabels.

value

character vector of dimlabels to be added to x. If `dimlabels<-` is used on its own, then the length of value must be the same as ndim. If `dimlabels<-` is used in confunction with the subsetting function `[[<-` or `[<-`, then the length of values should be equal to the length of dimlabels after from the subsetting. This is the same way `names<-` works.

Value

Like other similar functions (e.g., `names<-` and `[<-`), it does not appear to have a return object. However, it technically does as a side effect. The argument x will have been changed such that value has been added as dimlabels. If a traditional return object is desired, and no side effects, then it can be called like a traditional function: obj2 <- 'dimlabels<-'(x = obj, value = dimlab).

Examples

a <- array(c(letters, NA), dim = c(3,3,3),
   dimnames = replicate(3, expr = 1:3, simplify = FALSE))
dimlabels(a) <- c("first","second","third")
dimlabels(a)[[2]] <- c("2nd")
dimlabels(a)[c(1,3)] <- c("1st","3rd")
print(a)

[Package str2str version 1.0.0 Index]