igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Creating an exportable, labelled object from centrality mea


From: Gábor Csárdi
Subject: Re: [igraph] Creating an exportable, labelled object from centrality measures
Date: Fri, 11 Apr 2014 09:21:48 -0400

On Thu, Apr 10, 2014 at 5:03 PM, Stephen Cranney <address@hidden> wrote:
I went back to the object I created before, and it looks like the closeness command creates an object that doesn't have the country ids, even before I make it a data.frame. Can this really be the case? 

No, if you use a recent version of igraph:

library(igraph)
g <- graph.ring(10)
V(g)$name <- letters[1:10]
closeness(g)
#    a    b    c    d    e    f    g    h    i    j 
# 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 
 
That igraph just calculates the closeness statistics but doesn't match them up with the node ids? 

c_1996<-closeness(network, mode="in")

In regards to the specific command suggested, I'm getting the error below:

Error in data.frame(V(network)$name, c_1996) : 
  arguments imply differing number of rows: 0, 208"

Because your graph does not have vertex names.

I tried adding more rows (c_1996$id<-rep(0,times=208), but it's still giving me the error.  

Thanks again for the help, 

Please consider including a reproducible example, and then we can help better.

Gabor
 
 

Stephen 



On Thu, Apr 10, 2014 at 9:13 AM, Gábor Csárdi <address@hidden> wrote:
Hi Stephen,

it seems that data.frame() drops the names. So put the labels explicitly in the data frame, either as row names:

row.names(c_1996) <- V(network)$name

Or, if that does not work, as a separate column:

c_1996<-data.frame(V(network)$name, c_1996)

I don't have stata, so I cannot try this...

Gabor


On Thu, Apr 10, 2014 at 8:26 AM, Stephen Cranney <address@hidden> wrote:
Hi all,

I'm trying to export an object consisting of centrality measures I calculated to a Stata file. Specifically, my nodes are countries and I want the centrality measure associated with the particular country in the object so that I can export it to Stata with one column being country ids and the other column being the centrality measure for that particular country.

 However, for some reason when I calculate the centrality measure the labels do not appear to be attached, so when it is exported to Stata all that I get is one column of centrality measures unattached to any country ids. Below is my code; I'm a newbie to both R and igraph so apologies if this is a very simple question.

Thanks,

Stephen

network<-read.graph("TradeTransitions_pajek_1996.net", format = "pajek")
c_1996<-closeness(network, mode="in")
c_1996<-data.frame(c_1996)
is.data.frame(c_1996)
write.dta(c_1996, "d:/Users/scranney/Desktop/TradeTransitions/c_1996.dta")



--
Stephen Cranney

PhD Student
Graduate Group in Demography
University of Pennsylvania

_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help



_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help




--
Stephen Cranney

PhD Student
Graduate Group in Demography
University of Pennsylvania

_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help



reply via email to

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