igraph-help
[Top][All Lists]

## Re: [igraph] degree according to vertex attributes

 From: Dominik Santner (CRIE) Subject: Re: [igraph] degree according to vertex attributes Date: Mon, 01 Oct 2012 12:25:19 +0200 User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1

```Hello Tamás,

I just solved my problems:

```
I solved the first problem by simply adding an argument (delete.vertices=F) to subgraph.edges.
```
```
The second problem was solved this way (maybe its not the most elegant way, but it works):
```
```
To receive a graph with empty labels I exported it and reimported it immediately:
```
write.graph(xxx, "temp.net", format="pajek")

Then I added the city attribute of the original graph to my new graph:

V(xxx2)\$st_AMR <- V(xxx)\$st_AMR

And everything works fine!

Thank you very much for your previous help!

Best regards,

Dominik

Am 29.09.2012 11:56, schrieb Dominik Santner (CRIE):
```
```Hello,

```
thank you very much for your suggestion. Unfortunately there are two problems:
```
first:
when using your example graph created by

```
```g <- grg.game(100, 0.2)
V(g)\$city <- LETTERS[(0:99 %/% 10) + 1]
```
```
I recieve a warning when doing

```
```degree(g)-degree(internal.graph)
```
```
telling me that the two objects are not of the same length

```
```length(degree(internal.graph))
```
```[1] 96
```
```length(degree(g))
```
```[1] 100

the second problem occures when applying this procedure to my data:

in your example you use V(g)\$city when doing

```
```internal.edges <- which(V(g)\$city[el[,1]] == V(g)\$city[el[,2]])
```
```
whith the result:
```
```internal.edges
```
```  [1]   1   5   6   7   8 ...

when checking for
```
```V(g)\$city
```
```  [1] "A" "A" "A" "A" "A" ...

```
```V(g)\$city[el[,2]]
```
```  [1] "A" "B" "B" "B" "A" "A" ...

everything is fine.

But with my dataset this happens:

```
```internal.edges <- which(V(xxx)\$st_AMR[el[,1]] == V(xxx)\$st_AMR[el[,2]])
internal.edges
```
```integer(0)

```
```V(xxx)\$st_AMR
```
[1] "München" "Darmstadt" "Regensburg" "Halle" ...
```
```
```V(xxx)\$st_AMR[el[,2]]
```
```  [1] NA NA NA NA NA ...

```
Maybe it has something to do with my vertex labels and/or my edge list, but I have no idea what it might be:
```
The edge list of your example:

```
```head(el)
```
```     [,1] [,2]
[1,]    1    7
[2,]    1   11
[3,]    1   12
[4,]    1   13
[5,]    2    3
[6,]    2    4

The edge list of my dataset:

```
```head(el)
```
```     [,1]
[1,] "Company A (6411000)"
[2,] "Company A (6411000)"
[3,] "Company A (6411000)"
[4,] "Company A (6411000)"
[5,] "Company A (6411000)"
[6,] "Company A (6411000)"
[,2]
[1,] "University A (8416041)"
[2,] "University B (8416041)"
[3,] "Company B (5562024)"
[4,] "Company C (5358024)"
[5,] "Company D (5358024)"
[6,] "Company E (8215101)"

Best regards
Dominik

Am 28.09.2012 23:44, schrieb Tamás Nepusz:
```
```Hello,

```
Suppose that the city is encoded in the "city" vertex attribute of the graph; for instance:
```
```
```g <- grg.game(100, 0.2)
V(g)\$city <- LETTERS[(0:99 %/% 10) + 1]
```
```First, we get the edge list of the graph:

```
```el <- get.edgelist(g)
```
Next, we select those edges (i.e. rows) from the edge list where the endpoints are in the same city:
```
```
```internal.edges <- which(V(g)\$city[el[,1]] == V(g)\$city[el[,2]])
```
```We then create a subgraph which consists of these edges only:

```
```internal.graph <- subgraph.edges(g, internal.edges)
```
degree(internal.graph) will then give you how many friends each person has in the same city, and degree(g)-degree(internal.graph) will give you how many friends each person has in different cities.
```
Best,
```
```
```
```

```