dista: Distance between vectors and a matrix

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/dista.R

Description

Distance between vectors and a matrix.

Usage

1
dista(xnew, x, type = "euclidean", trans = TRUE)

Arguments

xnew

A matrix with some data or a vector.

x

A matrix with the data, where rows denotes observations (vectors) and the columns contain the variables.

type

This can be either \"euclidean\" or \"manhattan\".

trans

Do you wan the returned matrix to be transposed? TRUE or FALSE.

Details

The target of this function is to calculate the distances between xnew and x without having to calculate the whole distance matrix of xnew and x. The latter does extra calculaitons, which can be avoided.

Value

A matrix with the distances of each xnew from each vector of x. The number of rows of the xnew and and the number of columns of xnew are the dimensions of this matrix.

Author(s)

Michail Tsagris

R implementation and documentation: Michail Tsagris <mtsagris@yahoo.gr> and Manos Papadakis <papadakm95@gmail.com>.

See Also

mahala, Dist, total.dist, total.dista

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
xnew <- as.matrix( iris[1:10, 1:4] )
x <- as.matrix( iris[-c(1:10), 1:4] )
a <- dista(xnew, x)
b <- as.matrix( dist( rbind(xnew, x) ) )
b <- b[ 1:10, -c(1:10) ]
sum( abs(a - b) )

## see the time
x <- matrix( rnorm(1000 * 4), ncol = 4 )
system.time( dista(xnew, x) )
system.time( as.matrix( dist( rbind(xnew, x) ) ) )

Rfast documentation built on July 22, 2017, 1:02 a.m.

Search within the Rfast package
Search all R packages, documentation and source code