View source: R/structural.properties.R

edge_density | R Documentation |

The density of a graph is the ratio of the actual number of edges and the largest possible number of edges in the graph, assuming that no multi-edges are present.

```
edge_density(graph, loops = FALSE)
```

`graph` |
The input graph. |

`loops` |
Logical constant, whether loop edges may exist in the graph. This affects the calculation of the largest possible number of edges in the graph. If this parameter is set to FALSE yet the graph contains self-loops, the result will not be meaningful. |

The concept of density is ill-defined for multigraphs. Note that this function does not check whether the graph has multi-edges and will return meaningless results for such graphs.

A real constant. This function returns `NaN`

(=0.0/0.0) for an
empty graph with zero vertices.

Gabor Csardi csardi.gabor@gmail.com

Wasserman, S., and Faust, K. (1994). Social Network Analysis: Methods and Applications. Cambridge: Cambridge University Press.

`vcount()`

, `ecount()`

, `simplify()`

to get rid of the multiple and/or loop edges.

Other structural.properties:
`bfs()`

,
`component_distribution()`

,
`connect()`

,
`constraint()`

,
`coreness()`

,
`degree()`

,
`dfs()`

,
`distance_table()`

,
`feedback_arc_set()`

,
`girth()`

,
`is_dag()`

,
`is_matching()`

,
`knn()`

,
`laplacian_matrix()`

,
`reciprocity()`

,
`subcomponent()`

,
`subgraph()`

,
`topo_sort()`

,
`transitivity()`

,
`unfold_tree()`

,
`which_multiple()`

,
`which_mutual()`

```
g1 <- make_empty_graph(n = 10)
g2 <- make_full_graph(n = 10)
g3 <- sample_gnp(n = 10, 0.4)
# loop edges
g <- make_graph(c(1, 2, 2, 2, 2, 3)) # graph with a self-loop
edge_density(g, loops = FALSE) # this is wrong!!!
edge_density(g, loops = TRUE) # this is right!!!
edge_density(simplify(g), loops = FALSE) # this is also right, but different
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.