igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] subgraph by passing list of nodes that grabs also nodes po


From: Gábor Csárdi
Subject: Re: [igraph] subgraph by passing list of nodes that grabs also nodes pointing to that list
Date: Thu, 14 May 2009 10:24:09 +0200

Jose,

On Thu, May 14, 2009 at 8:28 AM, Jose Quesada <address@hidden> wrote:
> Gábor Csárdi wrote:
>
> Thanks Gabor,
>> there are many ways to do this, perhaps the simplest is to use
>> neighborhood() to collect the neighboring vertices and then call
>> subgraph().
>>
>> vv <- neighborhood(g, order=1, nodes=mynodes, mode="in")
>>
> hmm, this doesn't work on my network; it returns exactly the same list,
> mynodes, with no additional ones.
> I created the network by reading from a MatrixMarket file into a
> CsparseMatrix object with readMM, then constructing the graph from that
> matrix.
>
> I'm attaching a toy example, and code to reproduce the problem:
>
> library(igraph)
> library(Matrix)
>
> # Toy: just last few movies
> dataMtxFile = "movies2actors-10-idsOnly.mtx"
> # ma for movie actors
> matoy = as(readMM(paste(datapath, dataMtxFile, sep="")), "CsparseMatrix")
> tg = graph.incidence(matoy, directed=T, mode="out")
> mynodes =  1377253
> vv <- neighborhood(tg, order=1, nodes=mynodes, mode="in")
> vv
> #> vv
> #[[1]]
> #[1] 1377253 <- lists only the original node; misses five inbound
> connections.
> vv <- neighborhood(tg, order=1, nodes=mynodes, mode="all") #same for out
> vv # this lists all nodes but the ones that are actually connected to
> 1377253
> # [[1]]
> #  [1] 1377253 1413423 1457015 1464520 1517383 1641295 1704978 1741976
> 1744269 1744274 1744315 1745028 1745031 1756801 1783566
> # [16] 1803739 1836911 1836953 1836954 1836964 1836967 1844560 1848929
> 1880207 1946456 2132881 2203538 2278148 2282809 2324406
> # [31] 2409592 2409595 2410120 2410900 2681118 2946503 2946504 2946655
> 2974742
>
> What am I doing wrong?

It just seems that vertex 1377253 has no edges pointing to it, only
edges pointing to other vertices from it. If you use 'mode="out"' in
graph.incidence(), then all edges will point from 'type 1' vertices to
'type 2' vertices.

Do you really want to use a directed graph?

G.

> Thanks!
> -Jose
>> subgraph(g, unique(unlist(vv)))
>>
>> Best,
>> Gabor
>>
>
>
> --
> Jose Quesada, PhD.
> Max Planck Institute,
> Center for Adaptive Behavior and Cognition -ABC-,
> Lentzeallee 94, office 224, 14195 Berlin
> http://www.josequesada.name/
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
>



-- 
Gabor Csardi <address@hidden>     UNIL DGM




reply via email to

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