Learn R Programming

cba (version 0.1-6)

subset.dist: Subsetting Compact Symmetric Matrices

Description

This function conveniently returns a subset (submatrix) of an object of class dist.

Usage

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

x[[i]]

Arguments

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

Value

  • An object of class dist.

Warning

This is experimental code which may change in future releases.

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 objects which contain diagonal elements are not handled.

See Also

dist for details

Examples

Run this code
x <- as.dist(matrix(1:36, ncol=6))
subset(x, c(2,4,6))
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")]]

Run the code above in your browser using DataLab