0

I am trying to create an edge list with igraph for a co-authorship network analysis project. My data is stored in a way that every author of a specific paper is listen in rows, meaning that every paper is an observation and the columns contain the authors of that paper.

Is it possible to use the combn function to create an edge list of every combination of authors within each paper?

user3731465
  • 93
  • 1
  • 7
  • 3
    Why would you think it's not possible? What have you tried? Please edit your question to include sample input and desired output, or describe the problems you've had with your own code (why is the result you get not what you want). – MrFlick Jun 11 '14 at 19:22

1 Answers1

0

i guess you will have to do it one by one but you can put them all together using 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)
Seth
  • 4,745
  • 23
  • 27
pes
  • 56
  • 4