# weighted edge in degree calculation

**URL:** <https://igraph.discourse.group/t/weighted-edge-in-degree-calculation/1303>\
**Category:** Usage\
**Tags:** R\
**Created:** [22 July 2022 13:41 UTC](https://igraph.discourse.group/t/weighted-edge-in-degree-calculation/1303 "2022-07-22T13:41:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bc34556](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/bc34556/32/810_2.png) [@bc34556](https://igraph.discourse.group/u/bc34556)\
**Post date:** [22 July 2022 13:41 UTC](https://igraph.discourse.group/t/weighted-edge-in-degree-calculation/1303/1 "2022-07-22T13:41:35Z")

</div>

Hi, I want to know in a directed network, how igraph handles weighted edges when counting in-, out-, and total degrees?

---

<div class="post-metadata">

**Author:** ![KeesP](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@KeesP](https://igraph.discourse.group/u/KeesP)\
**Post date:** [23 July 2022 08:58 UTC](https://igraph.discourse.group/t/weighted-edge-in-degree-calculation/1303/2 "2022-07-23T08:58:16Z")

</div>

Note that:

- degree() calculates the number of neighbours for each selected vertex.
- strength() sums the edge weights of the adjacent edges for each selected vertex.

```auto
library(igraph)
g <- graph_from_literal(1-+2:3:4:5)
g
E(g)$weight <- 2
degree(g, mode="out")
strength(g, mode="out")
help(degree) # see doc
help(strength) # see doc

```

Output:

```auto
IGRAPH 46548af DNW- 5 4 -- 
+ attr: name (v/c), weight (e/n)
+ edges from 46548af (vertex names):
[1] 1->2 1->3 1->4 1->5

degrees:
1 2 3 4 5   
4 0 0 0 0 

strength:
1 2 3 4 5 
8 0 0 0 0

```

---

<div class="post-metadata">

**Author:** ![bc34556](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/bc34556/32/810_2.png) [@bc34556](https://igraph.discourse.group/u/bc34556)\
**Post date:** [11 August 2022 17:06 UTC](https://igraph.discourse.group/t/weighted-edge-in-degree-calculation/1303/3 "2022-08-11T17:06:50Z")

</div>

Thanks! This is super helpful!
