1

I'm new to programming in R and not very good so now I've got a question about my progect. I spend a lot of time in searching a specific code about "delete.edges". I want to delete specific edges from my graph, those with weight 0. I have make a txt in which i have 3 columns. the first and the second are the vertices kai the third is the weight. I wrote 0 in order to define no connection, 1,2,3 etc for connection. My graph is weighted. the plot gave me all of the posible edges including those with weight=0 and now i have to delete them and make a new plot.

Frank
  • 66,179
  • 8
  • 96
  • 180
maraki
  • 11
  • 1
  • 2
  • I use igraph igraph, Matrix and lattice. – maraki Apr 10 '16 at 16:15
  • when you make the edgelist, just don't include the rows with weight =0 when you make the graph? – jalapic Apr 10 '16 at 16:15
  • Show some code; make a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). It will be easer to help you that way. – MrFlick Apr 10 '16 at 16:16
  • the txt named "inn.txt" has the above form: node1 node2 applications Greece Australia 0 Greece Austria 1 Greece Belgium 0 Greece Canada 2 Greece Denmark 0 Greece Estonia 3 the code i have uses is: library(igraph) t1<- read.table("inn.txt", header = TRUE) flogE<- graph.data.frame(t1, dir=TRUE, vertices = NULL) flogE i tried the above code but it didn't help innov <- delete.edges(flogE, which(E(flogE)$weight != 0)-1) plot(innov) – maraki Apr 10 '16 at 16:34
  • If the column header of t1 is `applications`, you may need to change weight to that – jalapic Apr 10 '16 at 16:39
  • @jalapic "applications" is the meaning of the edge. zero means no applications with the other country, etc.. you mean that i have change the scale of numbers? for example to start from "1" if there is no connection between two countries? – maraki Apr 10 '16 at 16:50

1 Answers1

5

I made a random graph and then randomly assigned weight of 0,1,2,3. If you want to delete edges do in the following way:

library(igraph)
g<-erdos.renyi.game(100,p=.5)
E(g)$weight <- sample(0:3, length(E(g)),T)

delete.edges(g, which(E(g)$weight==0))
jalapic
  • 13,792
  • 8
  • 57
  • 87