R/jaccard.R

Defines functions jaccard

Documented in jaccard

#' Calculate Jaccard Index of two sets
#'
#' The `jaccard` function calculates the Jaccard Index of two sets.
#'
#' @param x,y Vectors of the same mode containing a sequence of non-duplicated
#' items.
#'
#' @return The Jaccard Index as a numeric value.
#'
#' @examples
#' ## NOT RUN
#' # jaccard(1:10, 1:20)
#'
#' @export
jaccard <- function(x, y) {
  length(intersect(x, y)) / (length(setdiff(x, y)) + length(setdiff(y, x)) +
                               length(intersect(x, y)))
}
Mengbo-Li/brainClass documentation built on March 16, 2023, 12:06 p.m.