简体   繁体   中英

Finding cosine similarity between dataframes using R

I have two data frames containing information from various hospitals. The first has number of probable cases of dengue and the second has number of comfirmed cases of dengues.The data is given weekly wise. I have data upto 53 weeks or 1 year. Example-

    Data Frame 1(Probable cases)
    HospitalName Week1 Week 2
         xyz       8     12
         abc       9      0
    Data Frame 2(Laboratory verified cases)
    HospitalName Week1 Week 2
         xyz       3     11
         abc      14      0

Both the data frames have the same names of hospitals in corresponding rows. I want to find the similarity between the two data frames using cosine similarity in R. How to do it?

install.packages("proxy")
dist(x,y,method = "cosine")

#       [,1]       [,2]      
#[1,] 0.03909305 0.44529980
#[2,] 0.23661371 0.00000000

x and y are Week1, Week2 from df1 and Week1, Week2 from df2

x <- as.matrix(Data Frame 1[,2:3])
y <- as.matrix(Data Frame 2[,2:3])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM