neighbors | R Documentation |
This function retrieves the indices of neighbors of one or more vertices in a given graph or graph-like object.
neighbors(x, i, ...)
x |
The graph or graph-like object in which to find the neighbors. |
i |
The vertex or vertices for which to find the neighbors. Can be a single vertex index or a vector of vertex indices. |
... |
Additional arguments to be passed to specific implementations of the neighbors method. |
A list of vertex indices representing the neighbors of the specified vertices. The length of the list is equal to the number of input vertices, and each element in the list contains the neighbor indices for the corresponding input vertex.
# Create an example graph
library(igraph)
g <- neighbor_graph(make_ring(5))
# Get neighbors of vertex 1
n <- neighbors(g, 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.