Вопрос по r – Найти общее количество второй переменной, связанной с расстоянием маршрута от get.shortest.paths ()

1

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

df2 = rbind(c(234,235,21.6,75),
c(234,326,11.0,35),
c(235,241,14.5,78),
c(326,241,8.2,98),
c(241,245,15.3,75),
c(234,245,38.46,65))

df2 = as.data.frame(df2)
names(df2) = c("start_id","end_id","newcost","distance")

df2

require(igraph)
g2 <- graph.data.frame(df2, directed=FALSE)

tkplot(g2)

(tmp2 = get.shortest.paths(g2, from='234', to='245',weights=E(g2)$newcost))

# This gives the shortest path based on $newcost
V(g2)[tmp2[[1]]]

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

# What is the distance related to the min newcost?

Ваш Ответ

1   ответ
1

Error: User Rate Limit Exceeded

optimal.path <- V(g2)[tmp2[[1]]] 
E(g2, path = optimal.path)
# Edge sequence:
#               
# [1] 326 -- 234
# [3] 241 -- 326
# [4] 245 -- 241

Error: User Rate Limit Exceededg2.)

Error: User Rate Limit Exceeded

sum(E(g2, path = optimal.path)$distance)
# [1] 208

Похожие вопросы