0

i have a two-mode network edgelist data like tmp below:

tmp <- read.table(text="PersonID CompanyID
P1 C000001
P2 C000001
P3 C000001
P4 C000001
P5 C000001
P6 C000002
P7 C000002
P8 C000002
P9 C000003
P10 C000003
P11 C000003
P12 C000003",header=TRUE)

# make a graph using this data
el <- graph.edgelist(as.matrix(tmp))

And I did this to add "type" attribute to create a bipartite graph in igraph

V(el)$type <- V(el)$name %in% el[,1]

But it turned that the type is all "false" and the names can't match. Does anyone know what's going wrong here?

> table(V(el)$type)
FALSE 
   15 

> V(el)$name
 [1] "P1"      "C000001" "P2"      "P3"      "P4"    "P5"    "P6"    "C000002"
 [9] "P7"      "P8"      "P9"      "C000003" "P10"   "P11"   "P12"  
thelatemail
  • 91,185
  • 12
  • 128
  • 188
  • If you have `V(el)$type <- V(el)$name %in% names(el[,1])` each element in `V(el)$type` is `TRUE`. But is this what you want? It is not clear to me yet what you are trying to accomplish. – user1981275 Apr 23 '13 at 08:22

1 Answers1

1

Instead of el[,1], use get.edgelist(el)[,1]. el[,1] is not the first column of the edge list as you may have expected; indexing a graph object like you did will in fact give you slices of the adjacency matrix instead.

Tamás
  • 47,239
  • 12
  • 105
  • 124