Learn R Programming

EGAnet (version 2.0.8)

cosine: Cosine similarity

Description

Computes cosine similarity

Usage

cosine(x, y = NULL, ...)

Arguments

x

Numeric vector, matrix, or data frame. If nrow(x) > 1, then x will be treated as a matrix to compute an n by n similarity matrix (y will not be used!)

y

Numeric vector, matrix, or data frame. Only used if x is a single variable. Used to compute similarity between one variable and n other variables. Defaults to NULL

...

Not actually used but makes it easier for general functionality in the package

Author

Alexander P. Christensen <alexpaulchristensen@gmail.com>

Details

On missing values: 0 will be used to replace missing values. When using (matrix) multiplication, the 0 value cancels out the product rendering the missing value as "not counting" in the sums

Examples

Run this code
# Load data
wmt <- wmt2[,7:24]

# Obtain cosines
wmt_cosine <- cosine(wmt)

Run the code above in your browser using DataLab