0

I am dealing with a problem that I am not able to understand where is the issue. I convert my data to a graph. I want to put degrees as a node attribute, but it wrongly performs it. when I perform dat<- as.data.frame(degree) this gives me correct answer, for example screen name of 2 node with highest degree(10) are "chrissmithonair" and "Philip_Huff" but when I perform V(graph)$screen_name[degrees %in% max_degree_nodes] it produce wrong answer, it means that degree are set wrongly as a node attribute.

Can anyone help me please?

sample of data that I am using:

https://www.dropbox.com/s/m1ysau37orv1vle/test.csv?dl=0
library(dplyr)
library("igraph")

df = read.csv(".../test.csv")
graph <- graph_from_data_frame(df %>% select("id","parent"),directed=F)
summary(graph)

graph <- graph%>%set_vertex_attr("id", value = df$id)
graph <- graph%>%set_vertex_attr("parent", value = df$parent)
graph <- graph%>%set_vertex_attr("screen_name", value = df$user.screen_name)

net<-asNetwork(graph)
net


degrees <- igraph::degree(graph) 
degree<-sort(degrees, decreasing = FALSE)
dat<- as.data.frame(degree). # it is correct

set_vertex_attr(
  graph,
  name = "degrees",
  value = igraph::degree(graph) 
)

max_degree_nodes <-10
V(graph)$screen_name[degrees %in% max_degree_nodes]. # it is wrong


Eli
  • 3
  • 4

0 Answers0