jeudi 5 février 2015

Generic method for converting a list to an edgelist


Vote count:

0




Let's say I have a list of strings:



list <- c("john", "carl", "suzanne")


Because they appear in the same list, I'm making a social network assumption that they are connected. In order to be able to convert this group to a graph, I need to make it to an edgelist:



from to
john carl
carl suzanne
suzanne john


The group, however, may contain 1-infinity strings. How do I construct a function that convert such a list of strings to an edgelist?


Spontaneously it seems that I can assign each string to a generic object (say, name, name2, and name3), and then just create a matrix as follows:



name1 = "john"
name2 = "carl"
name3 = "suzanne"
matrix(data = c(name1, name2, name2, name3, name1, name3), byrow=TRUE,
ncol=2)

[,1] [,2]
[1,] "john" "carl"
[2,] "carl" "suzanne"
[3,] "john" "suzanne"


However, this solution doesn't scale very well. How can I make a scaleable solution?



asked 30 secs ago







Generic method for converting a list to an edgelist

Aucun commentaire:

Enregistrer un commentaire