1

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.

4

1 回答 1

1

关于上述问题,我第一次在互联网上搜索时没有找到这个结果,但是,我现在才遇到它:

如何计算R中的邻接矩阵

从第一次检查来看,它似乎回答了我的问题。

于 2013-04-29T14:30:40.310 回答