[R] question about SNA in R, thanks!

Gábor Csárdi csardi at rmki.kfki.hu
Sat Dec 27 15:59:26 CET 2008


Please stay on the list to make the archive more useful. Here is the
conclusion of the thread.

Gabor

On Sat, Dec 27, 2008 at 2:59 PM, Weijia You <weijiawx at gmail.com> wrote:
> Sorry to trouble you, but I have got the answer to this problem.
> When I turn "el <- get.edgelist(g)" to "el <- get.edgelist(g,names=FALSE)",
> it works.
>
> Thank you very much for your help indeed!
> Enjoy your weekends!
> :)
>
> Weijia
>
>
> On Sat, Dec 27, 2008 at 9:36 PM, Weijia You <weijiawx at gmail.com> wrote:
>>
>> Thank you for your reply.
>> But it seems that there're still some problems with the function.
>> It always says "non-numeric argument to binary operator", and the
>> problem might be here "el[,1]+1"
>>
>> I attached the testfile I'm working on.
>> In the file I attached, first two columns are two users, for I
>> use userID to represent the users. And the third column is the weight of the
>> edge.
>>
>> Thank you for your attention and warm help.
>> Wish you a nice weekend!
>>
>> Weijia
>>
>> ----------------------------------------info from R
>> program----------------------------
>> > library(igraph)
>> > g1 <- read.graph("test/testr",format = "ncol", directed =TRUE)
>> > g1
>> Vertices: 25
>> Edges: 20
>> Directed: TRUE
>> Edges:
>>
>> [0]  100000 -> 112236
>> [1]  100000 -> 3058
>> [2]  100000 -> 35102
>> [3]  100000 -> 60211
>> [4]  100001 -> 19959
>> [5]  10000  -> 15205
>> [6]  10000  -> 152660
>> [7]  100002 -> 186035
>> [8]  100002 -> 3741
>> [9]  100002 -> 39770
>> [10] 100002 -> 61446
>> [11] 100002 -> 67689
>> [12] 100003 -> 25432
>> [13] 100003 -> 53184
>> [14] 10000  -> 35554
>> [15] 10000  -> 38719
>> [16] 100004 -> 178234
>> [17] 100004 -> 3058
>> [18] 100004 -> 71609
>> [19] 100004 -> 9910
>> > mixing <- function(g) {
>> +  el <- get.edgelist(g)
>> +  deg <- degree(g)
>> +  cor(deg[el[,1]+1], deg[el[,2]+1])
>> + }
>> > mixing(g1)
>> error: el[, 2] + 1 : non-numeric argument to binary operator
>> -----------------------------------------------------------------ends
>> here---------------------------------------
>>
>> On Sat, Dec 27, 2008 at 6:36 PM, Gábor Csárdi <csardi at rmki.kfki.hu> wrote:
>>>
>>> Weijia
>>>
>>> see ?degree for the degree and ?cor for the correlation. E.g.
>>>
>>> mixing <- function(g) {
>>>  el <- get.edgelist(g)
>>>  deg <- degree(g)
>>>  cor(deg[el[,1]+1], deg[el[,2]+1])
>>> }
>>>
>>> You need to modify the degree() call to take edge direction into account.
>>>
>>> Gabor
>>>
>>> ps. FYI, there is also an igraph missing list, in case I miss your
>>> messages on R-help and nobody else answers either.
>>>
>>> On Fri, Dec 26, 2008 at 5:48 PM, Weijia You <weijiawx at gmail.com> wrote:
>>> > Dear colleagues,
>>> >
>>> > I'm trying to have a look at the Assortative and Disassortative (
>>> > http://en.wikipedia.org/wiki/Assortative_mixing) of the network I have.
>>> > But it seems that the igraph hasn't mentioned that yet.
>>> >
>>> > I have to get the in/out degree of the vertices of each edge and
>>> > calculate
>>> > the Pearson's Correlation coefficient which seems to be quite a huge
>>> > task
>>> > for me. :(
>>> >
>>> > So I wonder if anyone had done that before and give me some hints on
>>> > it?
>>> >
>>> > Thank you in anticipation!
>>> >
>>> > Weijia
>>> >
>>> >        [[alternative HTML version deleted]]
>>> >
>>> > ______________________________________________
>>> > 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.
>>> >
>>>
>>>
>>>
>>> --
>>> Gabor Csardi <Gabor.Csardi at unil.ch>     UNIL DGM
>>
>
>



-- 
Gabor Csardi <Gabor.Csardi at unil.ch>     UNIL DGM



More information about the R-help mailing list