
Hi Sebastian,

See the graph.data.frame constructor as part of the igraph package.  You can easily extract a full vertex list and non-NA edge from your data frame, and this constructor allows you to read those right into a graph object.

library(igraph)

mydata <- read.csv('datafile.csv',header=T)

vertex.list <- data.frame(c(mydata$ego,mydata$alter))

vertex.list <- na.omit(unique(vertex.list))

edge.list <- na.omit(mydata)

g <- graph.data.frame(edge.list,vertices=vertex.list)

If you are trying to get rid of loops try using the simple command under igraph.

g2 <- simplify(g1, remove.loops=TRUE)

Best,
Gary


On May 19, 2011, at 6:00 AM, r-sig-networks-request@r-project.org wrote:

> Message: 4
> Date: Wed, 18 May 2011 16:50:36 -0500
> From: Sebasti?n Daza <sebastian.daza@gmail.com>
> To: Mathijs de Vaan <mathijsdevaan@gmail.com>
> Cc: r-sig-networks@r-project.org
> Subject: Re: [R-sig-networks] [R] data network format and grouping
> 	analysis
> Message-ID: <4DD43F2C.4080809@gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Thank you Mathijs, but now I have several graphs with loops that don't 
> mean anything. Isn't there another way to do it? Do you know about some 
> clear document that deals with these kind of data management problems in 
> R and sna?
> 
> Sebastian
> 
> On 5/18/2011 2:48 PM, Mathijs de Vaan wrote:
>> Simply add an edge between ego and ego for each ego.
>> 
>> Mathijs
>> 
>> 2011/5/18 Sebasti?n Daza <sebastian.daza@gmail.com
>> <mailto:sebastian.daza@gmail.com>>
>> 
>>    Thank you Scott.
>>    NA means there is no edge.  If I exclude NAs, I could lose isolated
>>    individuals. That's why my question. Each ego selected three friends
>>    in my database. If an ego didn't select any friend, it had only NAs
>>    in alter column. Any ideas?
>> 
>> 
>>    On 5/18/2011 2:33 PM, Scott Chamberlain wrote:
>> 
>>        The following works to get an igraph object from a matrix edgelist:
>> 
>>        dat2 <- matrix(rep(seq(1,5,1), 4), nrow=10, ncol=2)
>>        graph.edgelist( dat2 )
>> 
>> 
>>        I tried with NA's but graph.edgelist did not allow NA's.
>>        Wouldn't you
>>        just leave those rows out with NA's in them? An NA means there is no
>>        edge, right?
>> 
>>        Scott
>> 
>>        On Wednesday, May 18, 2011 at 1:23 PM, Sebasti?n Daza wrote:
>> 
>>            Hi everyone,
>>            I have a dataset of friendship with this format:
>> 
>>            ego alter
>>            4746 1 2
>>            9742 1 3
>>            14738 1 NA
>>            4747 2 NA
>>            9743 2 3
>>            14739 2 1
>>            4748 3 13
>>            9744 3 5
>>            14740 3 14
>>            4749 4 NA
>>            9745 4 NA
>>            14741 4 NA
>>            4750 5 NA
>>            9746 5 13
>>            14742 5 10
>>            4751 6 12
>>            9747 6 7
>>            ...
>> 
>> 
>>            NA means that individuals don't select any friend. DDoes
>>            anyone know how
>>            to format this dataset to use sna or igraph packages? I
>>            don't know how
>>            to convert it into a matrix or a edgelist in R without
>>            losing isolated
>>            individuals .
>> 
>>            Next question, anyone knows if there is a package to perform
>>            a Moody's
>>            Crowds routine to identify groups using R, or other
>>            algorithms designed
>>            to search groups by maximizing modularity scores?
>> 
>>            Thank you in advance!
>> 
>>            --
>>            Sebasti?n Daza
>>            sebastian.daza@gmail.com <mailto:sebastian.daza@gmail.com>
>>            <mailto:sebastian.daza@gmail.com
>>            <mailto:sebastian.daza@gmail.com>>
>> 
>>            ______________________________________________
>>            R-help@r-project.org <mailto:R-help@r-project.org>
>>            <mailto:R-help@r-project.org <mailto:R-help@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.
>> 
>> 
>> 
>>    --
>>    Sebasti?n Daza
>>    sebastian.daza@gmail.com <mailto:sebastian.daza@gmail.com>
>> 
>>    _______________________________________________
>>    R-sig-networks mailing list
>>    R-sig-networks@r-project.org <mailto:R-sig-networks@r-project.org>
>>    https://stat.ethz.ch/mailman/listinfo/r-sig-networks

--
Gary Weissman
http://www.babelgraph.org/
gary@babelgraph.org




	[[alternative HTML version deleted]]

