how would you present an adjacency list in R? he needs variable-sized lists for a set of neighboring nodes; so you need to use list (); but then what good is it in R?
I can think of lame tricks with similar functions, but they do a linear scan for each node. but playing for 1 minute, here is: a list of paired lists, where the second element of each pair is an adjacency list. the output is more crazy than it really is.
> edgelist=data.frame(A=c(1,1,2,2,2),B=c(1,2,2,3,4)) > library(plyr) > llply(1:max(edgelist), function(a) list(node=a, adjacents=as.list(edgelist$B[edgelist$A==a]))) [[1]] [[1]]$node [1] 1 [[1]]$adjacents [[1]]$adjacents[[1]] [1] 1 [[1]]$adjacents[[2]] [1] 2 [[2]] [[2]]$node [1] 2 [[2]]$adjacents [[2]]$adjacents[[1]] [1] 2 [[2]]$adjacents[[2]] [1] 3 [[2]]$adjacents[[3]] [1] 4 [[3]] [[3]]$node [1] 3 [[3]]$adjacents list() [[4]] [[4]]$node [1] 4 [[4]]$adjacents list()
Brendan oconnor
source share