cosSim: Cosine similarity

View source: R/cosSim.R

cosSimR Documentation

Cosine similarity

Description

Calculate cosine similarity between two vectors of the same length, or cosine similarity between two matrices

Usage

cosSim(x, ...)

## Default S3 method:
cosSim(x, y)

## S3 method for class 'matrix'
cosSim(x, y, all.vs.all = FALSE, by.row = TRUE)

## S3 method for class 'data.frame'
cosSim(...)

Arguments

x

A numeric vector or matrix

y

A numeric vector or matrix

all.vs.all

(When x and y are matrices) If TRUE, all rows of x are compared with all rows of y. If FALSE, rows of x are compared with rows of y 'side-by-side'

by.row

(When x and y are matrices) If TRUE, compare rows. If FALSE, compare columns

Value

A numeric vector or matrix

Examples

set.seed(1)
x <- matrix(runif(200), nrow=20)
y <- matrix(runif(200), nrow=20)

## Works with matrices
cosSim(x, y)

## ...or vectors
cosSim(x[1,], y[1,])


UMCUGenetics/mutSigExtractor documentation built on Aug. 30, 2024, 2:12 p.m.