the following table shows sales of different items a b c g at a grocery write r code 5151532
The following table shows sales of different items (A, B, C,….,G) at a grocery. Write R-codes possibly using “for” loops to calculate the Jaccard distance in order to compute similarities between all shopping basket pairs. Ex:The Jaccard distance for shopping baskets CA and CB is defined by
Shopping baskets | A | B | C | D | E | F | G |
CA | 5 | 0 | 0 | 0 | 2 | 1 | 2 |
CB | 2 | 1 | 2 | 0 | 0 | 0 | 0 |
CC | 0 | 0 | 1 | 4 | 0 | 0 | 1 |
CD | 0 | 0 | 2 | 0 | 1 | 1 | 2 |
CE | 6 | 2 | 2 | 0 | 1 | 1 | 2 |
CF | 4 | 0 | 0 | 2 | 0 | 0 | 2 |
I have got the following R-codes for the problem but mistakenly programmed for jaccard distance between shopping items instead of shopping baskets. Please help me to fix this small problem cause I am new to programming.
# reading the data from csv
groccery
#getting all column nameexcpet first one
b
#creating a list to store jacard distance for all pair
l
for(x in b){
for(y in b){
if(x!=y){
num
deno
l[[paste(x,y,sep = “”)]]
}
}
}
#printing jacard distacne for each paire
for(x in names(l)){
print(paste(x,l[[x]],sep = ” “),quote=FALSE)
cat(“n”)
}
CA n CB CA U CB