igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] removing NA's from graph object


From: Vicki Barclay
Subject: [igraph] removing NA's from graph object
Date: Tue, 24 Jul 2012 09:55:18 -0400

Hi, 

In igraph I have created a network with weighted edges, and I have set the 
vertex attributes.

I now want to use this graph object to calculate the assortativity of the 
network.

The problem is that some of my vertices are labeled NA (as we do not have the 
attribute information for those nodes).

igraph will not calculate the assortativity with the NA's present. I have tried 
na.omit(x) but this does not work.

Can someone suggest how I can remove the NA's from the g to be able to 
calculate the assortaitivity?

My code and the vertex output is as follows:

library(igraph)

accumul_d123.copy[,1]=as.character(accumul_d123.copy[,1]) 
accumul_d123.copy[,2]=as.character(accumul_d123.copy[,2])
accumul_d123.copy=as.matrix(accumul_d123.copy) 
g=graph.edgelist(accumul_d123.copy[,1:2],directed=FALSE) 
E(g)$weight=as.numeric(accumul_d123.copy[,3]) 
adj=get.adjacency(g,attr='weight')
adj
g

# import vaccination status file to label the nodes in g

g123 <- set.vertex.attribute(g,"vaccination", index=vacc_status_variant$V1, 
value=vacc_status_variant$V2) #labeled 123 as accumulated for days 1,2&3
get.vertex.attribute(g123, "vaccination")

#vertex attributes
[1]  1 NA  1  1  1  1  2  2 NA NA NA  2  2 NA  1 NA  1  1 NA  2  1  1 NA NA NA  
1  1  1  2 NA  1 NA  1
 [34] NA  1  2  2  1  1  1  1 NA NA  2  1  2  1  2 NA  1 NA  1 NA  1  1  1  2 
NA  1  1  1  1  2  1  2  1
 [67]  2 NA NA NA  2  1  2 NA NA NA NA  2  2  1 NA  1 NA NA  2 NA  1 NA  2  2  
1 NA NA NA NA  2  1  1 NA
[100]  2  1  1  2 NA NA  1  1 NA NA  1 NA  1  2 NA  2 NA  1  2  2 NA  2  1 NA 
NA NA  1  1 NA  2 NA  2  1
[133]  2 NA NA  2  2  1  1  2  2  2 NA NA  2 NA  2  2  2 NA  1  1 NA NA  2  1 
NA  1  1  1 NA NA NA NA  1
[166] NA NA  2 NA  1  2  2  1  1  1  1 NA  1  2 NA  1 NA  1 NA  2 NA  2  1  1  
2  2  1  2  1 NA  1 NA  2
[199]  1  1  2  1  1  1 NA NA  1  2 NA  1 NA  1  1  2 NA  2  2 NA  1  1  2  1 
NA NA NA  2 NA  2 NA  2  2
[232] NA NA  2 NA  2  1 NA  1 NA  1 NA  1 NA NA  1 NA NA  1 NA  2 NA NA  1  1  
2  1 NA  2  1 NA  2  1 NA
[265] NA  2 NA NA  1 NA  1 NA NA  2 NA NA NA  1  1  2  1 NA  1  1 NA  1 NA  2 
NA NA NA  2  1  2 NA  2  1
[298] NA  1  1 NA  1  2 NA NA  1 NA  2 NA NA  1 NA NA  1  1  1  1 NA  1  2  2 NA

assortativity(g123,V(g123)$vaccination,directed=F) # calculate assortativity 
for all cpr's
[1] NA

Thanks





reply via email to

[Prev in Thread] Current Thread [Next in Thread]