igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] reverse direction of connections


From: Sam Steingold
Subject: Re: [igraph] reverse direction of connections
Date: Tue, 30 Jul 2013 11:56:15 -0400

Thanks Gabor!
May I humbly suggest that you include this into the next release?

graph.reverse <- function (graph) {
  if (!is.directed(graph))
    return(graph)
  e <- get.data.frame(graph, what="edges")
  ## swap "from" & "to"
  neworder <- 1:length(e)
  neworder[1:2] <- c(2,1)
  e <- e[neworder]
  names(e) <- names(e)[neworder]
  graph.data.frame(e, vertices = get.data.frame(graph, what="vertices"))
}

would you like me to create a ticket for this?

On Mon, Jul 29, 2013 at 4:40 PM, Gábor Csárdi <address@hidden> wrote:
> On Mon, Jul 29, 2013 at 4:33 PM, Sam Steingold <address@hidden> wrote:
>>
>> >>> http://lists.gnu.org/archive/html/igraph-help/2009-03/msg00120.html
>> >> Is there an easy way to reverse direction of connections in a directed
>> >> graph?
>> >el <- get.edgelist(g, names=FALSE)
>> >g2 <- graph(rbind(el[,2],el[,1]))
>> >does the job, except that it loses all attributes.
>>
>> 4 years later, is there a better way (I want to keep the attributes,
>> obviously).
>
>
> get.data.frame() and then graph.data.frame() keeps the attributes.
>
> G.
>
>>
>>
>> Thanks!
>>
>> --
>> Sam Steingold (http://sds.podval.org/) on Ubuntu 13.04 (raring) X
>> 11.0.11303000
>> http://www.childpsy.net/ http://pmw.org.il http://americancensorship.org
>> http://www.memritv.org http://honestreporting.com http://memri.org
>> A professor is someone who talks in someone else's sleep.
>>
>> _______________________________________________
>> igraph-help mailing list
>> address@hidden
>> https://lists.nongnu.org/mailman/listinfo/igraph-help
>
>



-- 
Sam Steingold <http://sds.podval.org> <http://www.childpsy.net/>



reply via email to

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