Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dist2

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

x

A matrix or a list. If it is a matrix, the distance is calculated by rows.

pairwise_fun

A function which calculates distance between two vectors.

...

Pass to 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 for loops, so the efficiency may not be so good.

Value

A dist object.

Author(s)

Zuguang Gu <z.gu@dkfz.de>

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))
})

ComplexHeatmap

Make Complex Heatmaps

v2.6.2
MIT + file LICENSE
Authors
Zuguang Gu
Initial release
2020-11-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.