基于IGR图的数据帧邻接矩阵

基于IGR图的数据帧邻接矩阵,r,networking,graph,igraph,R,Networking,Graph,Igraph,我是R和graphs方面的新手,我正在尝试使用图书馆igraph使用社交签名网络进行练习 我有一个数据帧(df),它包含三列。第一个是投票者,第二个是收到选票的用户,第三个是选票(-1或1,分别取决于反对票或赞成票) 我想用igraph创建一个图,但首先我需要从df获得邻接矩阵 我试过用图书馆的神枪手 A <- component.adj.matrix(df[, c(1,2)], mu=df[, 1], co=df[, 2], wt=df[, 3]) A如果我没弄错你的问题,你可以使用i

我是R和graphs方面的新手,我正在尝试使用图书馆igraph使用社交签名网络进行练习

我有一个数据帧(df),它包含三列。第一个是投票者,第二个是收到选票的用户,第三个是选票(-1或1,分别取决于反对票或赞成票)

我想用igraph创建一个图,但首先我需要从df获得邻接矩阵

我试过用图书馆的神枪手

A <- component.adj.matrix(df[, c(1,2)], mu=df[, 1], co=df[, 2], wt=df[, 3])

A如果我没弄错你的问题,你可以使用
igraph
本身的
graph\u from\u data\u frame

数据

d <- structure(list(voter     = c("ludraman", "blankfaze", "gzornenplatz", "orthogonal", 
                                  "andrevan", "texture"), 
                    user      = c("cjcurrie", "olivo", "cjcurrie", "olvion", "cerviz", "cjcurrie"), 
                    vote      = c(1L, -1L, 1L, 1L, 1L, 1L)), 
                    row.names = c("1", "2", "3", "4", "5", "6"), class = "data.frame")

d如果我没弄错你的问题,你可以使用
igraph
本身的
graph\u from\u data\u frame

数据

d <- structure(list(voter     = c("ludraman", "blankfaze", "gzornenplatz", "orthogonal", 
                                  "andrevan", "texture"), 
                    user      = c("cjcurrie", "olivo", "cjcurrie", "olvion", "cerviz", "cjcurrie"), 
                    vote      = c(1L, -1L, 1L, 1L, 1L, 1L)), 
                    row.names = c("1", "2", "3", "4", "5", "6"), class = "data.frame")

d此解决方案适用于我的问题:

edge_list <- training_edges[df].                # create a edge list
G <- graph.data.frame(edge_list, directed=TRUE) # create the graph

A <- as_adjacency_matrix(G,type="both",names=TRUE,
sparse=FALSE, attr = "vote")                    # create the adjacency matrix

edge\u list此解决方案适用于我的问题:

edge_list <- training_edges[df].                # create a edge list
G <- graph.data.frame(edge_list, directed=TRUE) # create the graph

A <- as_adjacency_matrix(G,type="both",names=TRUE,
sparse=FALSE, attr = "vote")                    # create the adjacency matrix

edge\u列表谢谢!但是我的数据库太长了。我不能用手写下所有的名字和投票。你可以尝试
dput(head(你的数据,行数))
这会给你一个输出,你可以简单地复制并粘贴到这里。谢谢!但是我的数据库太长了。我不能手工写下所有的名字和投票。你可以尝试
dput(head(你的数据,行数))
,它会给你一个输出,你可以简单地复制并粘贴到这里。请将你的答案贴在下面,而不是问题里面。请将你的答案贴在下面,而不是问题里面。