siml_idx: Measure of the similarity index between two vectors

View source: R/siml_idx.R

siml_idxR Documentation

Measure of the similarity index between two vectors

Description

This functions returns a numeric vector length 1.

Usage

siml_idx(x, y, method, vorder)

Arguments

x

a character or binary vector

y

a character or binary vector

method

One of the "jaccard", "simpson", "dice", "smc", and "tanimoto"

vorder

The 'x' and 'y' are oredered vectors or not.

Value

a numeric vector

Examples

# character vector
v1 <- c("a", "b", "c", "d")
v2 <- c("a", "b", "e", "f")
siml_idx(v1, v2, method="jaccard")
siml_idx(v1, v2, method="simpson")
siml_idx(v1, v2, method="smc")
siml_idx(v1, v2, method="dice")

# Two sets of different size
v1 <- c("a", "b", "c")
v2 <- c("a", "b", "d", "e")
siml_idx(v1, v2, "smc")

# ordered categorical vector
ov1 <- c("3", NA,  NA,  "3", "2", "2")
ov2 <- c("3", "3", "2", "2", "2", "3")
siml_idx(ov1, ov2, "jaccard", TRUE)

# binary vector
bin1 <- c(1, 1, 1, 1, 0, 0, 0)
bin2 <- c(1, 1, 0, 0, 1, 1, 0)
siml_idx(bin1, bin2, method="jaccard")
siml_idx(bin1, bin2, method="simpson")
siml_idx(bin1, bin2, method="smc")
siml_idx(bin1, bin2, method="dice")

# numeric vector
n1 <- c(4.47, 4.35, 4.94, 3.09)
n2 <- c(3.86, 5.95, 5.48, 5.18)
siml_idx(n1, n2, method="tanimoto")
siml_idx(n1, n2, method="cosine")


shkonishi/rsko documentation built on Feb. 21, 2023, 5:12 a.m.