# clusteringCoefficient-methods: Clustering coefficient of a graph In graph: graph: A package to handle graph data structures

## 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

 ```1 2``` ```## 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)

Wolfgang Huber http://www.dkfz.de/mga/whuber

## Examples

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

### Example output

```Loading required package: BiocGenerics

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

IQR, mad, sd, var, xtabs

The following objects are masked from 'package:base':

Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, cbind, colMeans, colSums, colnames, do.call,
duplicated, eval, evalq, get, grep, grepl, intersect, is.unsorted,
lapply, lengths, mapply, match, mget, order, paste, pmax, pmax.int,
pmin, pmin.int, rank, rbind, rowMeans, rowSums, rownames, sapply,
setdiff, sort, table, tapply, union, unique, unsplit, which,
which.max, which.min

a         b         c         d         e         f         g         h
0.5238095 0.7333333       NaN 1.0000000 1.0000000 0.7333333 1.0000000 0.6666667
i         j
1.0000000 1.0000000
a         b         c         d         e         f         g         h
0.4489796 0.6111111 0.0000000 0.8000000 0.8000000 0.6111111 0.5000000 0.5555556
i         j
0.5000000 0.5000000
```

graph documentation built on Nov. 8, 2020, 6:02 p.m.