array2vector {spgs}R Documentation

Convert Arrays and Tables to Vectors with Named Elements

Description

Convert an array/table into an integer vector, preserving the names corresponding to each element in a sensible way. These functions differ from as.vector in that they name each element of the resulting vector by combining appropriate names from the various dimensions that together uniquely identify the position of each element in the original array/table.

Usage

array2vector(x, sep=".", sort=FALSE, rev=FALSE, ...)
table2vector(x, sep=".", sort=FALSE, rev=FALSE, ...)

Arguments

x

an array or table.

sep

a character string to be used to separate the name corresponding to each dimension when constructing the element names for the vector. The default value is ".".

sort

Should the elements in the resulting vector be sorted in lexicographic order according to the names they are assigned? The default is FALSE.

rev

For the purposes of sorting, should the names of the vector's elements be read from right-to-left, i.e. in reverse order? The default is FALSE.

...

Arguments to be passed from or to other functions.

Details

table2vector is merely a convenience alias for array2vector, which converts a multi-dimensional array or table to a vector using as.vector, but names each of the elements in the resulting vector according to the names contained in its dimnames attribute.

the name of each element is constructed by concatenating names (one from each dimnames member) seperated by the value specified in sep.

Note that dimensions of x which lack a corresponding vector of names in the dimnames attribute will be assigned a names vector of the form 1:d where d is the dimension size specified in the corresponding entry of the dim attribute.

Value

An integer vector with names set as described in ‘Details’.

Author(s)

Andrew Hart and Servet Martínez

See Also

pair.counts, triple.counts, quadruple.counts, cylinder.counts

Examples

a <- array(1:8, dim=rep(2,3), dimnames=list(c("a","b"), c("x","p"), c("v","u")))
array2vector(a)
array2vector(a, sep="")
array2vector(a, sep="", sort=TRUE)
array2vector(a, sep="", sort=TRUE, rev=TRUE)
array2vector(a, sep="", sort=TRUE, decreasing=TRUE)

[Package spgs version 1.0-4 Index]