使用igraph读取具有隔离节点的邻接表 [英] Reading adjacency lists with isolated nodes using igraph

查看:132
本文介绍了使用igraph读取具有隔离节点的邻接表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用igraph探索一些网络数据.我的数据具有以下结构:

I would like to use igraph to explore some network data. My data have this structure:

a <- c(13, 32, NA, NA)
b <- c(32, NA, NA, NA)
c <- c(34, 13, 32, NA)
d <- c(5, NA, NA, NA)

net <- rbind(a, b, c, d)

第一列:重点科目ID 从2到4列:焦点对象的接收者

First column: focal subject id From 2 to 4 columns: receivers from focal subject

在情节中,应隔离主题5.

In the plot, subject 5 should be isolated.

library(reshape)
library(igraph)

net <- as.data.frame(net)
mdata <- melt(net, id=c("V1"))
g <- graph.data.frame(mdata[,c(1,3)])  

Warning message:
In graph.data.frame(mdata[, c(1, 3)]) :
In `d' `NA' elements were replaced with string "NA"  

plot(g)

不出所料,NA作为一个节点出现.有关如何处理此问题的任何想法?

As expected, NA appears as a node. Any ideas on how to deal with this?

推荐答案

我必须分别定义顶点和边:

I had to define vertices and edges separately:

v <- unique(net[, 1])
mdata <- melt(net, id=c("V1"))
e <- na.omit(mdata[,c(1,3)])

g <- graph.data.frame(e, vertices=v, directed=TRUE)
plot(g)

这篇关于使用igraph读取具有隔离节点的邻接表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆