Hi, I am trying to construct a social network from a data frame with rows acra numa acrb numb year expab eabo impab iabo 10 USA 2 CAN 20 1957 4017.000 0.0 3187.000 0.0 91 USA 2 CUB 40 1957 628.000 0.0 526.000 0.0 144 USA 2 HAI 41 1957 25.000 0.0 20.000 0.0 and so on. I want the network to have directed edges from node acra to node acrb weighted by expab. What is the most convenient way to construct this network object? Thank you very much! Best, -- Johannes Urpelainen
> I am trying to construct a social network from a data frame with rows > > acra numa acrb numb year expab eabo impab iabo > 10 USA 2 CAN 20 1957 4017.000 0.0 3187.000 0.0 > 91 USA 2 CUB 40 1957 628.000 0.0 526.000 0.0 > 144 USA 2 HAI 41 1957 25.000 0.0 20.000 0.0 > > and so on. > > I want the network to have directed edges from node acra to node acrb > weighted by expab. What is the most convenient way to construct this > network object?Depends, I expect, on what you want to do with it. Building a matrix from acra to acrb with expab as the matrix value (aka "tie strength") wouldn't be all that crazy. Depending on which of the R network bits you are choosing to use, and the size of your data, different strategies are going to be more suitable than others. Generally there is good support for converting different representations - edgelist, matrix, etc - and between them. Some of those conversion methods don't work so well if the data is very large, however... you'll find that the ones that rely on processing a full matrix are particularly problematic, I expect. --elijah [School of Library and Information Science, Indiana University Bloomington]
Johannes, with the igraph package, this would be something like library(igraph) g <- graph.data.frame( data.frame(from=data$acra, to=data$acrb, weight=data$expab)) Gabor On Sun, Sep 23, 2007 at 11:39:40AM -0400, Johannes Urpelainen wrote:> Hi, > > I am trying to construct a social network from a data frame with rows > > acra numa acrb numb year expab eabo impab iabo > 10 USA 2 CAN 20 1957 4017.000 0.0 3187.000 0.0 > 91 USA 2 CUB 40 1957 628.000 0.0 526.000 0.0 > 144 USA 2 HAI 41 1957 25.000 0.0 20.000 0.0 > > and so on. > > I want the network to have directed edges from node acra to node acrb > weighted by expab. What is the most convenient way to construct this > network object? > > Thank you very much! > > Best, > > -- > Johannes Urpelainen > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Csardi Gabor <csardi at rmki.kfki.hu> MTA RMKI, ELTE TTK
there are several packages that can be used: the graph, RBGL and Rgraphviz packages, provide data structures, algorithms, and layout/plotting tools for graphs/networks. There are quite a few more specialized packages at Bioconductor (typically more related to biological problems). There, you can use biocViews to see what is available. best wishes Robert Johannes Urpelainen wrote:> Hi, > > I am trying to construct a social network from a data frame with rows > > acra numa acrb numb year expab eabo impab iabo > 10 USA 2 CAN 20 1957 4017.000 0.0 3187.000 0.0 > 91 USA 2 CUB 40 1957 628.000 0.0 526.000 0.0 > 144 USA 2 HAI 41 1957 25.000 0.0 20.000 0.0 > > and so on. > > I want the network to have directed edges from node acra to node acrb > weighted by expab. What is the most convenient way to construct this > network object? > > Thank you very much! > > Best, >-- Robert Gentleman, PhD Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M2-B876 PO Box 19024 Seattle, Washington 98109-1024 206-667-7700 rgentlem at fhcrc.org