0

I need to find the nearest neighbors of nodes in a network. I use the following coding from guideline of CRAN.

# count of nodes
n <- 10
# indexes(integer) of nodes for which neighbors should be searched
node.idxs <- c(1L, 5L)
# the adjaceny matrix (does not need to be symmetric)
graph <- rbind(cbind(0, diag(n-1)), 0)
# compute the neighbors until depth 3
neighs <- nearest.neighbors(node.idxs, graph, 3)

It finds the neighbors for the index of the nodes which are listed in node.idxs. Can anybody explain why (1L, 5L) has L for indexes. If I remove 'L', it does't work. I need to find the nearest neighbors for all the nodes of the network which I have. I need to change this line for passing dynamic list of indexes.How can I do so?

Anu
  • 211
  • 1
  • 9
  • For an overview of 1 vs 1L, [see this answer](https://stackoverflow.com/questions/7014387/whats-the-difference-between-1l-and-1), with some sparse info on indices. – Anonymous coward Apr 04 '18 at 19:52
  • Thank you. I already checked it. However, is it the same concept here. It just for index. isn't it? – Anu Apr 04 '18 at 20:12
  • It looks to me like it is calling those as index points, but why it doesn't work without the L, I can't say. I don't know. It makes it an integer, rather than numeric. I'd like to know why that matters when indexing, myself. – Anonymous coward Apr 04 '18 at 22:33

0 Answers0