Objective: I want to count the number of incoming edges of a partial type for each node. How can I do that?
Criteria:
- I need to use the R package tidygraph
- Answers that allow me to mutate an existing graph via a magrittr pipeline are better
- Fewer lines of code are better
The following code will generate an example graph
g <- play_erdos_renyi(n = 20, p = .10) %>%
activate(edges) %>%
mutate(type = sample(c('a', 'b', 'c'), size = n(), replace = T))
Ideal output, when searching (for example) for incoming g edges if type "a" would look like:
Node type_a_edges
X 3
Y 1
Z 4
...
EDIT: Added a figure to make the problem more concrete.
Here is an
tidygraph
+dplyr
optionwhich gives counts of all type "A" of inwards edges
If you want to have full information of all nodes, you can try the code below
which gives