Methods computing the nearest neighbour indices and distances for
matrix and MSnSet instances.
signature(object = "matrix", k = "numeric", dist =
"character", ...) Calculates indices and distances to the
k (default is 3) nearest neighbours of each feature (row)
in the input matrix object. The distance dist can
be either of "euclidean" or
"mahalanobis". Additional parameters can be passed to the
internal function FNN::get.knn. Output is a matrix with
2 * k columns and nrow(object) rows.
signature(object = "MSnSet", k = "numeric", dist =
"character", ...) As above, but for an MSnSet
input. The indices and distances to the k nearest
neighbours are added to the object's feature metadata.
signature(object = "matrix", query = "matrix", k =
"numeric", ...) If two matrix instances are provided as
input, the k (default is 3) indices and distances of the
nearest neighbours of query in object are returned
as a matrix of dimensions 2 * k by
nrow(query). Additional parameters are passed to
FNN::get.knnx. Only euclidean distance is available.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | library("pRolocdata")
data(dunkley2006)
## Using a matrix as input
m <- exprs(dunkley2006)
m[1:4, 1:3]
head(nndist(m, k = 5))
tail(nndist(m[1:100, ], k = 2, dist = "mahalanobis"))
## Same as above for MSnSet
d <- nndist(dunkley2006, k = 5)
head(fData(d))
d <- nndist(dunkley2006[1:100, ], k = 2, dist = "mahalanobis")
tail(fData(d))
## Using a query
nndist(m[1:100, ], m[101:110, ], k = 2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.