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

clusteringCoefficient-methods

Clustering coefficient of a graph


Description

This generic function takes an object that inherits from the graph class. The graph needs to have edgemode=="undirected". If it has edgemode=="directed", the function will return NULL.

Usage

## S4 method for signature 'graph'
clusteringCoefficient(object, selfLoops=FALSE)

Arguments

object

An instance of the appropriate graph class.

selfLoops

Logical. If true, the calculation takes self loops into account.

Details

For a node with n adjacent nodes, if selfLoops is FALSE, the clustering coefficent is N/(n*(n-1)), where N is the number of edges between these nodes. The graph may not have self loops. If selfLoops is TRUE, the clustering coefficent is N/(n*n), where N is the number of edges between these nodes, including self loops.

Value

A named numeric vector with the clustering coefficients for each node. For nodes with 2 or more edges, the values are between 0 and 1. For nodes that have no edges, the function returns the value NA. For nodes that have exactly one edge, the function returns NaN.

Author(s)

Examples

set.seed(123)
g1 <- randomGraph(letters[1:10], 1:4, p=.3)
clusteringCoefficient(g1)
clusteringCoefficient(g1, selfLoops=TRUE)

graph

graph: A package to handle graph data structures

v1.68.0
Artistic-2.0
Authors
R. Gentleman, Elizabeth Whalen, W. Huber, S. Falcon
Initial release

We don't support your browser anymore

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