Learn R Programming

phm (version 2.1.2)

textDist_sparse: Calculate Text Distance (sparse version)

Description

When two vectors are given, this calculates the text distance between them; text distance is calculated as the proportion of unmatched frequencies, i.e., the number of unmatched frequencies divided by the total frequencies among the two vectors. However, if neither vector has any values at all, their distance equals the number provided in the zeroes argument, which is .5 by default. When two matrices are given, the text distance between corresponding columns is calculated.

Usage

textDist_sparse(xi, xx, yi, yx, zeroes = 0.5)

Value

the text distance between the vectors x and y.

Arguments

xi

An integer vector with the row ids of the vector x

xx

A numeric vector with the values of the nonzero elements of x

yi

An integer vector with the row ids of the vector y

yx

A numeric vector with the values of the nonzero elements of y

zeroes

Text distance when both vectors are zero vectors; default is .5

Examples

Run this code
x=c(1,0,0,2,4,0,0,0,2,1,0,0)
y=c(2,0,0,0,2,0,0,1,0,3,1,0)
textDist_sparse(which(x!=0),x[x!=0],which(y!=0),y[y!=0])

Run the code above in your browser using DataLab