I am sorry. I try it again.
I wish to subset a graph by an arry of vertex ids ( in my example this is
zu). My subset should comprise my vertices of interest (zu) and the next
neighouring vertices.

Example:
a-----b-----c------d-------e
       |      |
       f     g

vertices of interest: c and d
I get:  b-c-d-e
             |
            g
Typing
induced.subgraph (g, zu)
generates a graph with the vertices (of zu) and with edges only between the
(subsetted) vertices (of zu). I want a subset that includes the vertices
(of zu) and all the edges of the vertices (of zu) and the corresponding
vertices.
I tried:
idx <- unique (as.vector (g[zu, edges=TRUE])) # get edges ids for vertices
of interest
idx <- idx[-1] # remove 0
ggzu <- subgraph.edges (g, idx)
And the results are okay but I guess its is  very clumsy.

Thanks

 dput (ggzu)
structure(list(3, FALSE, c(1, 2, 2), c(0, 0, 1), c(0, 1, 2),
    c(0, 1, 2), c(0, 0, 1, 3), c(0, 2, 3, 3), list(c(1, 0, 1),
        structure(list(), .Names = character(0)), structure(list(
            name = c("16052513", "16052618", "rs3013006"), x = c(16052513L,
            16052618L, 16054667L), y = c(2.547104, 1.587586,
            1.543943)), .Names = c("name", "x", "y")), structure(list(
            weight = c(0.725426, 0.681783, 0.86216), color = c("blue",
            "grey", "red")), .Names = c("weight", "color")))), class =
"igraph")


2014-02-04 Gábor Csárdi <[email protected]>:

> Hi, to be honest I have no idea what you want. Can you give a small
> example? E.g. what is the expected output of your example graph?
>
> Gabor
>
>
> On Tue, Feb 4, 2014 at 1:51 PM, Hermann Norpois <[email protected]>wrote:
>
>> Hello,
>>
>> I have an igraph object g and I want to subset g by using vertex ids, for
>> instance by
>>
>>  zu
>> [1] "16052618"  "rs3013006".
>>
>> I want to keep all edges of each defined vertix, also the edges my
>> vertices share with other vertices. So induced.subgraph is not an option,
>> isn't it?
>>
>> I tried subgraph.edges but I guess my approach is very clumsy. So I ask
>> for an amelioration.
>>
>> I tried:
>>
>> idx <- unique (as.vector (g[zu, edges=TRUE])) # get edges ids for
>> vertices of interest
>> idx <- idx[-1] # remove 0
>> ggzu <- subgraph.edges (g, idx)
>>
>> Do you have any suggestions?
>> Thanks
>> Hermann
>>
>>
>>
>> dput (g)
>> structure(list(9, FALSE, c(6, 2, 7, 8, 7, 5), c(0, 1, 1, 1, 2,
>> 3), c(1, 5, 0, 2, 4, 3), c(0, 1, 2, 3, 4, 5), c(0, 0, 0, 1, 1,
>> 1, 2, 3, 5, 6), c(0, 1, 4, 5, 6, 6, 6, 6, 6, 6), list(c(1, 0,
>> 1), structure(list(), .Names = character(0)), structure(list(
>>     name = c("16052361", "16052513", "16052618", "16052962",
>>     "rs11703994", "rs62224614", "rs78724352", "rs3013006", "rs55926024"
>>     ), x = c(16052361L, 16052513L, 16052618L, 16052962L, 16053791L,
>>     16053862L, 16053863L, 16054667L, 16054740L), y = c(2.156147,
>>     2.547104, 1.587586, 4.037532, 3.734964, 5.026869, 2.514876,
>>     1.543943, 0.579408)), .Names = c("name", "x", "y")), structure(list(
>>     weight = c(0.526203, 0.725426, 0.681783, 0.579408, 0.86216,
>>     0.718093), color = c("grey", "blue", "grey", "grey", "red",
>>     "blue")), .Names = c("weight", "color")))), class = "igraph")
>>
>>     dput (zu)
>> c("16052618", "rs3013006")
>>
>> _______________________________________________
>> igraph-help mailing list
>> [email protected]
>> https://lists.nongnu.org/mailman/listinfo/igraph-help
>>
>>
>
> _______________________________________________
> igraph-help mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>
>
_______________________________________________
igraph-help mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/igraph-help

Reply via email to