0
我正在嘗試使用igraph爲共同作者網絡分析項目創建邊界列表。我的數據以特定紙張的每位作者按行進行收聽的方式進行存儲,這意味着每張紙張都是一種觀察結果,列中包含該紙張的作者。從R中的協作網絡創建邊界列表
是否可以使用combn函數在每篇論文中創建每個作者組合的邊界列表?
我正在嘗試使用igraph爲共同作者網絡分析項目創建邊界列表。我的數據以特定紙張的每位作者按行進行收聽的方式進行存儲,這意味着每張紙張都是一種觀察結果,列中包含該紙張的作者。從R中的協作網絡創建邊界列表
是否可以使用combn函數在每篇論文中創建每個作者組合的邊界列表?
我想你將不得不做它一個接一個,但你可以把它們放在一起使用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)
爲什麼你會認爲這是不可能的?你有什麼嘗試?請編輯您的問題以包含示例輸入和所需輸出,或者描述您使用自己的代碼所遇到的問題(爲什麼結果不是您想要的)。 – MrFlick