I am trying to calculate the queue size in a network in R. For that at first I calculate the betweenness centrality of all the nodes in the network which returns a vector. For calculating the queue, I have to do a summation of all the betweenness value for all the nodes and multiply it with some other values which will be constant in my case. I have tried to use a for loop and my code is given below:
between <- betweenness(graphList[[1]], v=V(graphList[[1]]), directed =TRUE, weights = NULL,nobigint = TRUE, normalized = FALSE)
S <- length (between)
A <- 0
for(i in 1:length(S))
{
A = A + sum (d * l * between [i]/(S - 1 - (d * l * between [i])) )
}
Now the value A returns for only the first value of between, not the entire vector. Is there any other way to calculate this? Can anyone help me on this?
Your problem is that when you call length(S) as your loop variable, you are taking the length of the length of between, ie if length(between) is 29, S = 29 and length(S) is 1. Therefore you only get 1 loop. You can change it to:
for(i in 1:S)....
And it will work.
BUT:
All the calculations you are doing on between are vectorised, so there is no need for a loop:
library(igraph)
set.seed(24)
g <- random.graph.game(10, 3/10)
between <- betweenness(g)
S <- length (between)
A <- 0
d <- 0.5 #not sure what value you had
l <- 0.5 #not sure again
A <- sum((d * l * between /(S - 1 - (d * l * between)) ))
A
[1] 1.219178
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With