-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathdist2.Rd
36 lines (34 loc) · 905 Bytes
/
dist2.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
\name{dist2}
\alias{dist2}
\title{
Calculate Pairwise Distance from a Matrix
}
\description{
Calculate Pairwise Distance from a Matrix
}
\usage{
dist2(x, pairwise_fun = function(x, y) sqrt(sum((x - y)^2)), ...)
}
\arguments{
\item{x}{A matrix or a list. If it is a matrix, the distance is calculated by rows.}
\item{pairwise_fun}{A function which calculates distance between two vectors.}
\item{...}{Pass to \code{\link[stats:dist]{as.dist}}.}
}
\details{
You can construct any type of distance measurements by defining a pair-wise distance function.
The function is implemented by two nested \code{for} loops, so the efficiency may not be so good.
}
\value{
A \code{\link[stats]{dist}} object.
}
\author{
Zuguang Gu <[email protected]>
}
\examples{
lt = lapply(1:10, function(i) {
sample(letters, sample(6:10, 1))
})
dist2(lt, function(x, y) {
length(intersect(x, y))/length(union(x, y))
})
}