Reputation: 21
I have a graph generated by following code:
library(igraph)
dat <- data.frame(
V0 = c(0L, 100L, 200L, 0L, 0L, 0L, 0L),
V2 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L),
V3 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L),
V4 = c(120L, 0L, 0L, 0L, 0L, 0L, 0L),
V6 = c(0L, 0L, 0L, 30L, 0L, 0L, 0L),
V10 = c(180L, 0L, 0L, 90L, 0L, 0L, 0L),
V12 = c(0L, 0L, 0L, 0L, 30L, 270L, 0L))
rownames(dat) <- c("V0","V2","V3","V4","V6","V10","V12")
dat <- data.matrix(dat)
g2 <- graph_from_adjacency_matrix(dat, weighted=TRUE)
plot(g2, vertex.size = 20, edge.label = E(g2)$weight)
The graph should look like this:
My expected output is to calculate the Weighted In-Degree, Weighted Out-Degree. Thank you a lot
Upvotes: 0
Views: 732
Reputation: 50678
You're looking for igraph::strength
with mode = "in"
and mode = "out"
.
strength(g2, mode = "in")
# V0 V2 V3 V4 V6 V10 V12
#300 0 0 120 30 270 300
strength(g2, mode = "out")
# V0 V2 V3 V4 V6 V10 V12
#300 100 200 120 30 270 0
See also the manual.
Upvotes: 2