我有一张图:
> graf
IGRAPH 12ffd7b UNW- 16 16 --
+ attr: name (v/c), color (v/c), weight (e/n)
+ edges from 12ffd7b (vertex names):
[1] 0--1 0--2 0--15 2--3 2--4 2--5 2--7 2--8 2--10 2--11 2--12 2--14 4--6 4--9 8--13 1--5
licznik是4个寻找邻居的媒介
licznik [1] "8" "3" "1" "7"
for (v in licznik)
{
y<- neighbors(graf,v)
print(y)
zarazeni1 <- c(zarazeni1, y)
}
wspolne = c(zarazeni1)
结果“ wspolne”,它给出2个结果,第一行是好结果(与图形一致),不幸的是他还收到了第二个结果,这是不正确的
> wspolne
2 13 2 0 5 2
"2" "16" "2" "1" "8" "2"
我犯错的地方
编辑
dput(graf)
structure(list(16, FALSE, c(4, 1, 5, 6, 2, 7, 8, 3, 9, 10, 11,
12, 13, 14, 15, 7), c(0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
2, 3, 4), c(1, 4, 7, 0, 2, 3, 5, 15, 6, 8, 9, 10, 11, 12, 13,
14), c(1, 0, 2, 4, 7, 3, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15),
c(0, 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16
), c(0, 3, 12, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16), list(c(1, 0, 1), structure(list(), .Names = character(0)),
structure(list(name = c("0", "2", "4", "8", "1", "15",
"3", "5", "7", "10", "11", "12", "14", "6", "9", "13"
), color = c("green", "green", "green", "blue", "blue",
"green", "blue", "green", "blue", "green", "green", "green",
"green", "green", "green", "green")), .Names = c("name",
"color")), structure(list(weight = c(0.0478016305714846,
0.731876280624419, 0.282143459422514, 0.998805105453357,
0.814432282699272, 0.957247303100303, 0.734987537842244,
0.41236763051711, 0.645621495554224, 0.488656249130145,
0.0478016305714846, 0.731876280624419, 0.282143459422514,
0.998805105453357, 0.814432282699272, 0.957247303100303
)), .Names = "weight")), class = "igraph")