spatialEco (version 1.3-2)

csi: Cosine Similarity Index

Description

Calculates the cosine similarity and angular similarity on two vectors or a matrix

Usage

csi(x, y = NULL)

Arguments

x

A vector or matrix object

y

If x is a vector, then a vector object

Value

If x is a matrix, a list object with: similarity and angular.similarity matrices or, if x and y are vectors, a vector of similarity and angular.similarity

Examples

Run this code
# NOT RUN {
# Compare two vectors (centered using scale)
  x=runif(100)
  y=runif(100)^2
  csi(as.vector(scale(x)),as.vector(scale(y)))
  
  #' # Compare columns (vectors) in a matrix (centered using scale)
  x <- matrix(round(runif(100),0),nrow=20,ncol=5)
  ( s <- csi(scale(x)) )
    
# Compare vector (x) to each column in a matrix (y)
y <- matrix(round(runif(500),3),nrow=100,ncol=5)
x=runif(100) 
csi(as.vector(scale(x)),scale(y))

# }

Run the code above in your browser using DataLab