Calculating average path length for each vertex contingent on it sharing an edge with another vertex with a specific attribute

-I am using social network data on individuals arrested with those arrested together representing a social tie with one another. The data is in an igraph class. The individual vertices have an attribute on whether they were the victim of a shooting.

  • I am attempting to get the average path lengths of each individual vertex in the network if they share an edge or edges with the victim of a shooting OR a vertex that has an edge with a gunshot victim. Conceptually, the process will look something like this (which each number representing how many degrees they are away from another vertex) Matrix with Victim and non-victims. I want this data to be placed in a dataframe like this with each node representing an observation and a column showing the average distance to a victim enter image description here. If a vertex does not share an edge they would have a zero in that column.