0

I have a data.frame with 3 columns, 1st and 2nd columns represents Edge list and 3rd column represent weights. I used graph.data.frame(data.frame) for getting graph.

#df: data frame
g<- graph.data.frame(df1, directed=F)
E(g)$weight<- df1[,3]
View(df1)

0 11 315.39
0 66 366.68
0 128 95.6
0 233 117.58
0 437 205.5
..........
..........
..........

3rd column is the weights that i hv assigned to g Now if i do

df2<- get.data.frame(g)

it is giving an extra 4th column named weights as follows

0  11   315.39  34 
0  66   366.68  35
0  128  95.6    3
0  233  117.58  10 
0  437  205.5   19
..................
..................
..................

I understood that the R has took the unique weights and numbered it in sequence and 4th column gives the respective sequence number of the weight. Finally i simplified my graph

g<- simplify(g)
df3<- get.data.frame(g)
View(df3)
0  11   34 
0  66   35
0  128  3
0  233  10 
0  437  19
..........
..........
..........

Now my weights are gone.... Why it is so....? What if i do some community discovery (fastgreedy, multilevel) algorithm on the graph g? would that consider my original weights ?

  • What's `class(df1[,3])`? Are you sure your weights are numeric and not factors? You should provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data so we can run the code to se what's going on. – MrFlick Feb 25 '16 at 15:10
  • ok fine class was factor ... changed it to numerical... and now its working fine... Thanks @MrFlick – Vimal Pournami Feb 25 '16 at 17:09

0 Answers0