Reputation: 1101
I am trying to get basic stats from a not-directed igraph object I created. When using the simple degree function i get negative numbers, what went wrong?
col_1 <- as.vector(as.character(df$names_1))
col_2 <- as.vector(as.character(df$names_2))
vector <- rbind(col_1,col_2)
g <- graph(vector, directed = FALSE)
head(sort(desc(degree(g, loops = FALSE, normalized = FALSE))))
Sorry for not being able to produce an example because of privacy issue. Thanks
Upvotes: 0
Views: 118
Reputation: 37661
degree
does not produce negative numbers. desc
does.
Since you do not provide any data, I will illustrate with an arbitrary graph.
library(igraph)
library(plyr)
set.seed(1234)
g = erdos.renyi.game(15, 0.2)
degree(g, loops = FALSE, normalized = FALSE)
[1] 3 3 5 1 5 4 2 6 4 3 3 5 3 1 6
desc(degree(g, loops = FALSE, normalized = FALSE))
[1] -3 -3 -5 -1 -5 -4 -2 -6 -4 -3 -3 -5 -3 -1 -6
If you want to sort the degrees in descending order try
sort(degree(g, loops = FALSE, normalized = FALSE), decreasing=TRUE)
[1] 6 6 5 5 5 4 4 3 3 3 3 3 2 1 1
Upvotes: 2