In R, I need to get the number of layers below each node in a tree. If my data are:
from,to
A,Z
B,Z
C,A
D,A
E,A
F,D
G,D
H,G
I,C
The results should be:
A 3
B 0
C 1
D 2
E 0
F 0
G 1
H 0
I 0
Z 4
I've been trying to figure something out with data.tree
but I can't seem to figure it out, and not sure what other packages would be helpful here. Any help would be much appreciated.