I'm hoping for some more transformation help. Say I have a data frame:
df = data.frame(source = c("a","a","b"),
target = c("b","c","d"),
weight = c(1,1,1))
where the row: source = i | target = j | weight = w
denotes a directed edge of weight w
from node i
to node j
.
Given an arbitrary data frame of this form, I am looking for a procedure to investigate the components of the induced graph G
. Having read a comment by Ben on this question by me:
R: Gephi: manipulating dataframe to use with write.gexf
I checked out the package sna
which seemed to have what I was looking for in the form of the function component.dist
. So my question is 'how can I transform my data frame into a suitable form for the dat
argument of the component.dist
function (or is there a more 'optimum' way of approaching this problem?)' I tried the following code:
xtabs(weight ~ source + target, data = df)
but this has obvious shortfalls (e.g. it doesn't form an nrow(df)
by nrow(df)
matrix).
Thanks for any help.