I have the following data frame \'x\'
id,item,volume
a,c1,2
a,c2,3
a,c3,2
a,c4,1
a,c5,4
b,c6,6
b,c1,2
b,c3,1
b,c2,6
b,c4,4
c,c2,5
c,c8,6
c,c9,2
d,c1,1
e,c3,7
As @joran mentioned its kind of unclear what you really want. But If I understand correctly(probably not) I would like to propose an alternate route. I think you want a matrix of items to items with numbers representing the number of times the items share a customer?
If so then:
library(igraph)
library(tnet)
id_item<-cbind(
i=c(1,1,2,2,2,2,2,3,4,5,5,5,6,6,7,8), #items
p=c(1,2,1,2,3,4,5,2,3,4,5,6,6,7,8,8)) #customers
item_item<-projecting_tm(id_item, method="sum")
item_item <- tnet_igraph(item_item,type="weighted one-mode tnet")
itemmat<-get.adjacency(item_item,attr="weight")
itemmat #8x8 martrix of items to items
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#[1,] 0 2 1 0 0 0 0 0
#[2,] 2 0 1 1 2 0 0 0
#[3,] 1 1 0 0 0 0 0 0
#[4,] 0 1 0 0 0 0 0 0
#[5,] 0 2 0 0 0 1 0 0
#[6,] 0 0 0 0 1 0 0 0
#[7,] 0 0 0 0 0 0 0 1
#[8,] 0 0 0 0 0 0 1 0
If you need to take number of times the item was bought (volume) into account too then this is easily added into this code.