igraph (version 0.3.2)

neighborhood: Neighborhood of graph vertices

Description

These functions find the vertices not farther than a given limit from another fixed vertex, these are called the neighborhood of the vertex.

Usage

neighborhood.size(graph, order, nodes=V(graph), mode="all")
neighborhood(graph, order, nodes=V(graph), mode="all")
graph.neighborhood(graph, order, nodes=V(graph), mode="all")

Arguments

graph
The input graph.
order
Integer giving the order of the neighborhood.
nodes
The vertices for which the calculation is performed.
mode
Character constatnt, it specifies how to use the direction of the edges if a directed graph is analyzed. For out only the outgoing edges are followed, so all vertices reachable from the source vertex in at most order

Value

  • neighborhood.size returns with an integer vector.

    neighborhood returns with a list of integer vectors.

    graph.neighborhood returns with a list of graphs.

Details

The neighborhood of a given order o of a vertex v includes all vertices which are closer to v than the order. Ie. order 0 is always v itself, order 1 is v plus its immediate neighbors, order 2 is order 1 plus the immediate neighbors of the vertices in order 1, etc.

neighborhood.size calculates the size of the neighborhoods for the given vertices with the given order.

neighborhood calculates the neighborhoods of the given vertices with the given order parameter.

neighborhood is creates (sub)graphs from all neighborhoods of the given vertices with the given order parameter. This function preserves the vertex, edge and graph attributes.

Examples

Run this code
g <- graph.ring(10)
neighborhood.size(g, 0, 1:3)
neighborhood.size(g, 1, 1:3)
neighborhood.size(g, 2, 1:3)
neighborhood(g, 0, 1:3)
neighborhood(g, 1, 1:3)
neighborhood(g, 2, 1:3)

# attributes are preserved
V(g)$name <- c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")
graph.neighborhood(g, 2, 1:3)

Run the code above in your browser using DataCamp Workspace