如何计算所有成员对以进行网络分析?

How to compute all member pairs for network analysis?

我有关于在爵士乐专辑中表演的艺术家的 discogs 数据,我想创建这些人的网络地图。下面提供了示例数据。我需要计算给定专辑中所有可能的艺术家对。为了说明所需的结果,下图显示了原始数据(左侧)以及必须如何添加额外的行才能在专辑中获得所有可能对的唯一集合。必须保留有关角色的附加信息。在所示示例中,三张专辑最初有 12 条记录。重组后的数据将有 31 条记录和相同的列。

A​​ post 看起来很相似,但处理数据的结构不同。

jnet<-structure(list(leadArtist = c("Milt Jackson", "Milt Jackson", 
"Milt Jackson", "Milt Jackson", "Milt Jackson", "Milt Jackson", 
"Milt Jackson", "Milt Jackson", "Milt Jackson", "Milt Jackson", 
"Milt Jackson", "Milt Jackson"), albumid = c(2460190, 2460190, 
2460190, 2460190, 444693, 444693, 444693, 3019083, 3019083, 3019083, 
3019083, 3019083), extraArtists = c("Sahib Shihab", "Art Blakey", 
"Horace Silver", "Joe Newman", "Steve Novosel", "Vinnie Johnson", 
"Johnny O'Neal", "Percy Heath", "Lawrence Marable", "Skeeter Best", 
"John Lewis (2)", "Lucky Thompson"), role = c("Baritone Saxophone", 
"Drums", "Piano", "Trumpet", "Bass", "Drums", "Piano", "Bass", 
"Drums", "Guitar", "Piano", "Tenor Saxophone")), row.names = c(NA, 
-12L), class = c("tbl_df", "tbl", "data.frame"))

这里至少有一种方法。

Pairs = matrix("", nrow=0, ncol=2)
for(AID in unique(jnet$albumid)) {
    Selector = jnet$albumid == AID
    Artists = unique(c(jnet$leadArtist[Selector], 
                 jnet$extraArtists[Selector]))
    Pairs = rbind(Pairs, t(combn(Artists, 2)))
}
head(Pairs)
     [,1]           [,2]           
[1,] "Milt Jackson" "Sahib Shihab" 
[2,] "Milt Jackson" "Art Blakey"   
[3,] "Milt Jackson" "Horace Silver"
[4,] "Milt Jackson" "Joe Newman"   
[5,] "Sahib Shihab" "Art Blakey"   
[6,] "Sahib Shihab" "Horace Silver"