get_percentage_of_matches: Get percentage of matches between two vectors

View source: R/operations.R

get_percentage_of_matchesR Documentation

Get percentage of matches between two vectors

Description

Use this function on two numeric vectors with the same names attribute (columns) and same length, in order to find the percentage of common elements (value matches between the two vectors). The same names for the two vectors ensures that their values are logically matched one-to-one.

Usage

get_percentage_of_matches(vec1, vec2)

Arguments

vec1

numeric vector with names attribute

vec2

numeric vector with names attribute

Value

the percentage of common values (exact matches) between the two vectors. Can only be a value between 0 (no common elements) and 1 (perfect element match). Note that NaN and NA values are allowed in the input vectors, but they will always count as a mismatch.

Examples

vec1 = c(1, 2, 3, 2)
vec2 = c(20, 2, 2.5, 8)
vec3 = c(1, 2, 333, 222)
names.vec = c(seq(1,4))
names(vec1) = names.vec
names(vec2) = names.vec
names(vec3) = names.vec

match.1.2 = get_percentage_of_matches(vec1, vec2)
match.1.3 = get_percentage_of_matches(vec1, vec3)


usefun documentation built on Sept. 17, 2023, 9:06 a.m.