simMat | R Documentation |
The simMat
object is an internally utilized class that provides similar
functionality to the dist
object, but with matrix-like accessors.
Like dist
, this object stores values as a vector, reducing memory by
making use of assumed symmetry. simMat
currently only supports numeric
data types.
## Create a blank sym object
simMat(VALUE, nelem, NAMES=NULL, DIAG=FALSE)
## S3 method for class 'vector'
as.simMat(x, NAMES=NULL, DIAG=TRUE, ...)
## S3 method for class 'matrix'
as.simMat(x, ...)
## S3 method for class 'simMat'
print(x, ...)
## S3 method for class 'simMat'
as.matrix(x, ...)
## S3 method for class 'simMat'
as.data.frame(x, ...)
## S3 method for class 'simMat'
Diag(x, ...)
## S3 replacement method for class 'simMat'
Diag(x) <- value
VALUE |
Numeric (or |
nelem |
Integer; number of elements represented in the matrix. This corresponds to the
number of rows and columns of the object, so setting |
NAMES |
Character (Optional); names for each row/column. If provided, this should be
a character vector of length equal to |
DIAG |
Logical; Is the diagonal included in the data? If |
x |
Various; for |
value |
Numeric; value(s) to replace diagonal with. |
... |
Additional parameters provided for consistency with generic. |
The simMat
object has a very similar format to dist
objects, but
with a few notable changes:
simMat
objects have streamlined print
and show
methods to make displaying large matrices better. print
accepts an additional argument n
corresponding to the maximum number of rows/columns to print before truncating.
simMat
objects support matrix-style get/set operations like s[1,]
or s[1,3:5]
simMat
objects allow any values on the diagonal, rather than just
zeros as in dist
objects.
simMat
objects support conversion to matrices and data.frame
objects
simMat
objects implement get/set Diag()
methods. Note usage of capitalized Diag
; this is to avoid conflicts and weirdness with using base diag
.
See the examples for details on using these features.
The number of elements printed when calling print
or show
on a
simMat
object is determined by the "SynExtend.simMat"
option.
simMat
and as.simMat
return an object of class "simMat"
. Internally,
the object stores the upper triangle of the matrix similar to how dist
stores objects.
The object has the following attributes (besides "class"
equal to "simMat"
):
nrow |
the number of rows in the matrix implied by the vector |
NAMES |
the names of the rows/columns |
as.matrix(s)
returns the equivalent matrix to a "simMat"
object.
as.data.frame(s)
returns a data.frame
object corresponding to
pairwise similarities.
Aidan Lakshman ahl27@pitt.edu
## Creating a blank simMat object initialized to zeros
s <- simMat(0, nelem=20)
s
## Print out 5 rows instead of 10
print(s, n=5)
## Create a simMat object with 5 entries from a vector
dimn <- 5
vec <- 1:(dimn*(dimn-1) / 2)
s1 <- as.simMat(vec, DIAG=FALSE)
s1
## Here we include the diagonal
vec <- 1:(dimn*(dimn+1) / 2)
s2 <- as.simMat(vec, DIAG=TRUE)
s2
## Subsetting
s2[1,]
s2[1,3:4]
# all entries except first row
s2[-1,]
# all combos not including 1
s2[-1,-1]
## Replace values (automatically recycled)
s2[1,] <- 10
s2
## Get/set diagonal
Diag(s1)
Diag(s1) <- 5
s1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.