0

I am working on a problem to find the measures related to structure holes in R. The problem is that when I apply the code below to save the adjacency matrix to a variable called "x" (copied from that source) Adjacency matrix in R it gives me an error like:

"Error in as.data.frame.default(d) : cannot coerce class ""igraph"" to a data.frame"

My code and data set looks like this a data frame

s1
   uid1 uid2    
1     1    2    
2     1    3    
3     1    4    
4     1    5    
5     2    3   
6     2    4    
7     2    5    
8     3    4    
9     3    5    
10    4    5   
11    6    7    
12    6    8    
13    6    9    
14    7    8    
15    7    9    
16    8    9    
17    1    6   
18    1    7   
19    6    7

When I apply this code then the error becomes over here

x <- get.adjacency(graph.data.frame(graph.edgelist(as.matrix(s1), directed=F)))

Error in as.data.frame.default(d) : cannot coerce class ""igraph"" to a data.frame

So any help to use this code for the structure holes measure like

y <- index.egonet(x) #desired output is this code
Community
  • 1
  • 1
Naveed Khan Wazir
  • 185
  • 2
  • 4
  • 15
  • You're going from a data.frame to a matrix to an edgelist to a graph. Just go data.frame --> graph. `x <- get.adjacency(graph.data.frame(s1, directed=F))` – thelatemail May 12 '15 at 06:36
  • yep it works but when i apply this code it give me this error now index.egonet(x) Error in intI(i, n = d[1], dn[[1]], give.dn = FALSE) : invalid character indexing – Naveed Khan Wazir May 12 '15 at 06:43

1 Answers1

0

You are going

data.frame (s1)               -->  
   matrix                     --> 
     graph via graph.edgelist --> 
       trying to create a graph again via graph.data.frame

And that's why you're getting an error, because you already have a graph, and graph.data.frame() expects a data.frame as input, not an igraph object. That's what the error message is saying:

Error in as.data.frame.default(d) : cannot coerce class ""igraph"" to a data.frame

I.e - "don't give me an 'igraph' object, I want a data.frame"

The end conclusion of all this is - just go from your source data.frame to an igraph object, then extract the adjacency matrix:

get.adjacency(graph.data.frame(s1, directed=F))
thelatemail
  • 91,185
  • 12
  • 128
  • 188
  • your above suggestion is working but when i apply index.egonet to the adjacency matrix (X) it gives me an error.like index.egonet(x) Error in intI(i, n = d[1], dn[[1]], give.dn = FALSE) : invalid character indexing – Naveed Khan Wazir May 12 '15 at 07:11