Learn R Programming

memnet (version 0.1.0)

get_kneighbors: Get vector of neighbors exactly k steps away

Description

Function iterates over graph to identify for a given node all nodes that are exactly k steps apart.

Usage

get_kneighbors(adj, start, k = 1L)

Arguments

adj

numeric matrix specifying the adjacency matrix.

start

integer specifying the row index of the start node in the adjacency matrix.

k

integer specifying the exact distance to the start node.

Value

A numeric vector containing node indices of nodes k or fewer steps away from start.

Details

k < 1 will be set to k = 1.

Examples

Run this code
# NOT RUN {
# generate watts strogatz graph
network = grow_ws(n = 100, k = 10, p = .5)

# get neighborhood of second node
get_kneighbors(network, 2)

# get 3-hop neighborhood of second node
get_kneighbors(network, 2, k = 3)

# }

Run the code above in your browser using DataLab