共著ネットワーク分析プロジェクトのために igraph でエッジ リストを作成しようとしています。私のデータは、特定の論文のすべての著者が行で聞くように保存されています。つまり、すべての論文は観察であり、列にはその論文の著者が含まれています。
各論文内の著者のすべての組み合わせのエッジ リストを作成するために、combn 関数を使用することは可能ですか?
1つずつ実行する必要があると思いますが、 do.call('c',...) を使用してそれらをすべてまとめることができます
library(utils)
## original data as a list
data.in = list(c(1,2,3),c(4,5),c(3),c(1,4,6))
## function that makes all pairs
f.pair.up <- function(x) {
n = length(x)
if (n<2) {
res <- NULL
} else {
q <- combn(n,2)
x2 <- x[q]
#dim(x2) <- dim(q)
res <- x2
}
return(res)
}
## for each paper create all author pairs (as a flat vector)
data.pairs.bypaper = lapply(data.in,f.pair.up)
## remove papers that contribute no edges
data.pairs.noedge = sapply(data.pairs.bypaper,is.null)
data.pairs2.bypaper <- data.pairs.bypaper[!data.pairs.noedge]
## combine all 'subgraphs'
data.pairs.all <- do.call('c',data.pairs2.bypaper)
## how many authors are there?
n.authors <- length(unique(data.pairs.all))
## make a graph
my.graph = graph(data.pairs.all,directed=FALSE,n=n.authors)
## plot it
tkplot(my.graph)