elementwise | R Documentation |
Computes elementwise similarities/distances between two collections of objects (strings, vectors, etc.) using the provided comparator.
elementwise(comparator, x, y, ...) ## S4 method for signature 'CppSeqComparator,list,list' elementwise(comparator, x, y, ...) ## S4 method for signature 'StringComparator,vector,vector' elementwise(comparator, x, y, ...) ## S4 method for signature 'NumericComparator,matrix,vector' elementwise(comparator, x, y, ...) ## S4 method for signature 'NumericComparator,vector,matrix' elementwise(comparator, x, y, ...) ## S4 method for signature 'NumericComparator,vector,vector' elementwise(comparator, x, y, ...) ## S4 method for signature 'Chebyshev,matrix,matrix' elementwise(comparator, x, y, ...) ## S4 method for signature 'FuzzyTokenSet,list,list' elementwise(comparator, x, y, ...) ## S4 method for signature 'InVocabulary,vector,vector' elementwise(comparator, x, y, ...) ## S4 method for signature 'Lookup,vector,vector' elementwise(comparator, x, y, ...) ## S4 method for signature 'MongeElkan,list,list' elementwise(comparator, x, y, ...)
comparator |
a comparator used to compare the objects, which is a
sub-class of |
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 |
... |
other parameters passed on to other methods. |
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)}.
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.
This function is not strictly necessary, as the comparator
itself is a
function that returns elementwise vectors of scores. In other words,
comparator(x, y, ...)
is equivalent to
elementwise(comparator, x, y, ...)
.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.