# knn

From igraph v1.0.0
by Gabor Csardi

##### Average nearest neighbor degree

Calculate the average nearest neighbor degree of the given vertices and the same quantity in the function of vertex degree

- Keywords
- graphs

##### Usage

`knn(graph, vids = V(graph), weights = NULL)`

##### Arguments

- graph
- The input graph. It can be directed, but it will be treated as undirected, i.e. the direction of the edges is ignored.
- vids
- The vertices for which the calculation is performed. Normally it
includes all vertices. Note, that if not all vertices are given here, then
both
and`knn`

will be calculated based on the given`knnk`

- weights
- Weight vector. If the graph has a
`weight`

edge attribute, then this is used by default. If this argument is given, then vertex strength (see`strength`

) is used instead of vertex degree. But note

##### Details

Note that for zero degree vertices the answer in `knn`

`NaN`

(zero divided by zero), the same is true for `knnk`

##### Value

- A list with two members:
knn A numeric vector giving the average nearest neighbor degree for all vertices in `vids`

.knnk A numeric vector, its length is the maximum (total) vertex degree in the graph. The first element is the average nearest neighbor degree of vertices with degree one, etc.

##### References

Alain Barrat, Marc Barthelemy, Romualdo Pastor-Satorras, Alessandro Vespignani: The architecture of complex weighted networks, Proc. Natl. Acad. Sci. USA 101, 3747 (2004)

##### Examples

```
# Some trivial ones
g <- make_ring(10)
knn(g)
g2 <- make_star(10)
knn(g2)
# A scale-free one, try to plot 'knnk'
g3 <- sample_pa(1000, m=5)
knn(g3)
# A random graph
g4 <- sample_gnp(1000, p=5/1000)
knn(g4)
# A weighted graph
g5 <- make_star(10)
E(g5)$weight <- seq(ecount(g5))
knn(g5)
```

*Documentation reproduced from package igraph, version 1.0.0, License: GPL (>= 2)*

### Community examples

Looks like there are no examples yet.