Learn R Programming

comparator (version 0.1.3)

elementwise: Elementwise Similarity/Distance Vector

Description

Computes elementwise similarities/distances between two collections of objects (strings, vectors, etc.) using the provided comparator.

Usage

elementwise(comparator, x, y, ...)

# S4 method for CppSeqComparator,list,list elementwise(comparator, x, y, ...)

# S4 method for StringComparator,vector,vector elementwise(comparator, x, y, ...)

# S4 method for NumericComparator,matrix,vector elementwise(comparator, x, y, ...)

# S4 method for NumericComparator,vector,matrix elementwise(comparator, x, y, ...)

# S4 method for NumericComparator,vector,vector elementwise(comparator, x, y, ...)

# S4 method for Chebyshev,matrix,matrix elementwise(comparator, x, y, ...)

# S4 method for FuzzyTokenSet,list,list elementwise(comparator, x, y, ...)

# S4 method for InVocabulary,vector,vector elementwise(comparator, x, y, ...)

# S4 method for Lookup,vector,vector elementwise(comparator, x, y, ...)

# S4 method for MongeElkan,list,list elementwise(comparator, x, y, ...)

Value

Every object in x is compared to every object in y elementwise (with recycling) using the given comparator, to produce a numeric vector of scores of length \(max{size(x), size(y)}\).

Arguments

comparator

a comparator used to compare the objects, which is a sub-class of Comparator.

x, y

a collection of objects to compare, typically stored as entries in an atomic vector, rows in a matrix, or entries in a list. The required format depends on the type of comparator. If x and y do not contain the same number of objects, the smaller collection is recycled according to standard R behavior.

...

other parameters passed on to other methods.

Methods (by class)

  • comparator = CppSeqComparator,x = list,y = list: Specialization for CppSeqComparator where x and y are lists of sequences (vectors) to compare.

  • comparator = StringComparator,x = vector,y = vector: Specialization for StringComparator where x and y are vectors of strings to compare.

  • comparator = NumericComparator,x = matrix,y = vector: Specialization for NumericComparator where x is a matrix of rows (interpreted as vectors) to compare with a vector y.

  • comparator = NumericComparator,x = vector,y = matrix: Specialization for NumericComparator where x is a vector to compare with a matrix y of rows (interpreted as vectors).

  • comparator = NumericComparator,x = vector,y = vector: Specialization for NumericComparator where x and y are vectors to compare.

  • comparator = Chebyshev,x = matrix,y = matrix: Specialization for Chebyshev where x and y matrices of rows (interpreted as vectors) to compare. If x any y do not have the same number of rows, rows are recycled in the smaller matrix.

  • comparator = FuzzyTokenSet,x = list,y = list: Specialization for FuzzyTokenSet where x and y are lists of token vectors to compare.

  • comparator = InVocabulary,x = vector,y = vector: Specialization for InVocabulary where x and y are vectors of strings to compare.

  • comparator = Lookup,x = vector,y = vector: Specialization for a Lookup where x and y are vectors of strings to compare

  • comparator = MongeElkan,x = list,y = list: Specialization for MongeElkan where x and y lists of token vectors to compare.

Examples

Run this code
## Compute the absolute difference between two sets of scalar observations
data("iris")
x <- as.matrix(iris$Sepal.Width)
y <- as.matrix(iris$Sepal.Length)
elementwise(Euclidean(), x, y)

## Compute the edit distance between columns of two linked data.frames
col.1 <- c("Hasna Yuhanna", "Korina Zenovia", "Phyllis Haywood", "Nicky Ellen")
col.2 <- c("Hasna Yuhanna", "Corinna Zenovia", "Phyllis Dorothy Haywood", "Nicole Ellen")
elementwise(Levenshtein(), col.1, col.2)
Levenshtein()(col.1, col.2)               # equivalent to above

## Recycling is used if the two collections don't contain the same number of objects
elementwise(Levenshtein(), "Cora Zenovia", col.1)

Run the code above in your browser using DataLab