0

I convert the data frame to graph using igraph. when I want to set vertex attribute I get a warning and my vertex does not fit correctly to node. Can any one help me please? The problem also shows when I want to set degree as a node attribute and I would end up to a not correct result (NOT correctly set node degree as node attribute -R). How can I solve the warning?

sample of data that I am using:

https://www.dropbox.com/s/m1ysau37orv1vle/test.csv?dl=0
df = read.csv(".../test.csv")  # read csv file 
graph <- graph_from_data_frame(df %>% select("id","parent"),directed=F)
summary(graph)

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


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

set_vertex_attr(
  graph,
  name = "degrees",
  value = igraph::degree(graph) 
)
max_degree_nodes <-10

E(graph)$screen_name[degrees %in% max_degree_nodes]

The Warning:

> graph <- graph%>%set_vertex_attr("screen_name", value = df$user.screen_name)
Warning message:
In vattrs[[name]][index] <- value :
  number of items to replace is not a multiple of replacement length

Szabolcs
  • 24,728
  • 9
  • 85
  • 174
Eli
  • 3
  • 4
  • From what I can tell, df is an edge list. Igraph will then use that to enumerate a vertex list. Unless you have a strict tree with the root having itself as its own parent, your edge list will not be the same length as the number of vertices. Therefore if you try to use a column in df as the vector of values for the attributes, it will not be the same size as the number of vertices. My guess is this is a valid warning. – Marcus Jul 02 '21 at 15:19
  • thank you, how can I solve the issue? – Eli Jul 02 '21 at 17:23
  • is there any way that I can solve the issue? – Eli Jul 02 '21 at 18:42
  • Hey Marcus do you see my comment? – Eli Jul 03 '21 at 05:26

0 Answers0