# Jaccard index from a dataframe/array

I am trying to calculate the Jaccard Index of an array/DataFrame using the package Distance.jl, and am having difficulty.

``````using Distances, DataFrames

zxcv = [0.0 0.0 1.0;0.0 0.0 1.0;0.0 0.0 0.0]
dist = evaluate(jaccard(),zxcv[:,1],zxcv[:,2]) # error no method matching jaccard

``````

In R the formula is

``````zxcv<-c(0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0)
dim(zxcv)<-c(3,3)

trophic.sim = function(web){
# compute trophic similarity (Jaccard index)
# using the cocitation matrix approach
# cocite defines the cardinal of the intersection of prey and preds
cocite = web%*%t(web) + t(web)%*%web  # |a inter b|
# now calculate union as |a| + |b| - |a inter b|
web.degree = colSums(web) + rowSums(web) # |a| + |b|
nb_s = nrow(web)
sum.degree = outer(web.degree,web.degree, FUN = '+') # sum.degree contains |a| + |b|
web.union = sum.degree - cocite
obs.trophic.sim = cocite / web.union
return(obs.trophic.sim)
}

mat.similarity = trophic.sim(zxcv)
``````

Could someone show me how to use the Distance package correctly, or what the R code would look like in Julia?

I have no clue about your R code, but you can either use `jaccard(zxcv[:,1],zxcv[:,2])`
or replace the lowercase `j` with an uppercase one in your code.

When I use `dist = jaccard(zxcv[:,1],zxcv[:,2])` the result is `NaN`. When I use `dist = jaccard(zxcv[:,2],zxcv[:,3])` the result is 1. I was expecting an array as a result. I think the package is built to only return a single value, which is not what I need.