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,