subset.dist {cba}R Documentation

Subsetting Sparse Symmetric Matrices

Description

This function conveniently returns a subset (submatrix) of a sparse symmetric (distance) matrix.

Usage

## S3 method for class 'dist':
subset(x, subset, ...)
## S3 method for class 'dist':
x[[subset, ...]]

row.dist(x)
col.dist(x)

Arguments

x an object of class dist.
subset logical, character, or index vector.
... further (unused) arguments.

Details

For consistency, subsetting a symmetric matrix is constrained to a single index (vector). However, non-unique indexing is allowed. In this case zero is returned for diagonal elements.

If x has a Labels attribute a character vector can be used for subsetting.

Note that an error is raised if subset contains NA, or a non-finite value.

row.dist and col.dist return the matrix indexes of the row or columns, respectively.

Value

An object of class dist.

Warning

This is experimental code which may change in future releases.

Author(s)

Christian Buchta

See Also

dist for details.

Examples

x <- as.dist(matrix(1:36, ncol=6))
subset(x, c(2,4,6))
subset(x, c(4,2,6))               # same set but different order
attr(x, "Labels") <- letters[1:6] # hack!
subset(x, c(2,4,6))
subset(x, letters[c(2,4,6)])
subset(x, c(2,2,4,6))             # contains one zero 
# this is more user friendly
x[[c(2,4,6)]]
x[[c("b","d","e")]]
## finally, don't use NA, etc.
z <- try(x[[c(2,NA,6)]], silent=TRUE)
z
# this is arguable
x[[1]]                            # vector of length zero

# indexes
row.dist(x)
col.dist(x)

# convenience
dim(x)
dimnames(x) <- LETTERS[1:6]
dimnames(x)

[Package cba version 0.2-5 Index]