VSAT
VSAT

Reputation: 1

Compare text stored in each row across 2 columns in R

I have 2 vectors

a=c("abc","def","ghi","jkl")  
b=c("abc","dez","gyx","mno")

How can I get cosine values to compare corresponding entries? In this case, I need to be able to say the 1st entries in each vector is perfectly similar and 2nd entry in each vector is slightly similar... and the last entry in each vector is completely dissimilar? I tried the lsa package - but I can get an overall cosine value

Upvotes: -1

Views: 533

Answers (1)

Sotos
Sotos

Reputation: 51582

You can use stringdist package

stringdist(a, b, method = "cosine")
#[1] 0.0000000 0.3333333 0.6666667 1.0000000

Upvotes: 0

Related Questions