Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

edge_density

Graph density


Description

The density of a graph is the ratio of the number of edges and the number of possible edges.

Usage

edge_density(graph, loops = FALSE)

Arguments

graph

The input graph.

loops

Logical constant, whether to allow loop edges in the graph. If this is TRUE then self loops are considered to be possible. If this is FALSE then we assume that the graph does not contain any loop edges and that loop edges are not meaningful.

Details

Note that this function may return strange results for graph with multiple edges, density is ill-defined for graphs with multiple edges.

Value

A real constant. This function returns NaN (=0.0/0.0) for an empty graph with zero vertices.

Author(s)

References

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

See Also

vcount, ecount, simplify to get rid of the multiple and/or loop edges.

Examples

g1 <- make_empty_graph(n=10)
g2 <- make_full_graph(n=10)
g3 <- sample_gnp(n=10, 0.4)

# loop edges
g <- graph( c(1,2, 2,2, 2,3) )
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

igraph

Network Analysis and Visualization

v1.2.10
GPL (>= 2)
Authors
See AUTHORS file.
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.