---
title: covariance() function
description: covariance() computes the covariance between two columns.
url: https://docs.influxdata.com/flux/v0/stdlib/universe/covariance/
estimated_tokens: 383
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/universe/covariance/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.7.0+

InfluxDB support

`covariance()` computes the covariance between two columns.

##### Function type signature

```js
(<-tables: stream[A], columns: [string], ?pearsonr: bool, ?valueDst: string) => stream[B] where A: Record, B: Record
```

For more information, see [Function type signatures](/flux/v0/function-type-signatures/).

## Parameters

### columns

(Required)
List of two columns to operate on.

### pearsonr

Normalize results to the Pearson R coefficient. Default is `false`.

### valueDst

Column to store the result in. Default is `_value`.

### tables

Input data. Default is piped-forward data (`<-`).

## Examples

### Calculate the covariance between two columns

```js
data
    |> covariance(columns: ["x", "y"])
```

[](#view-example-input-and-output)

View example input and output

#### Input data

|       \_time       | x | y  |
|--------------------|---|----|
|2021-01-01T00:00:00Z| 0 | 0  |
|2021-01-01T00:00:12Z| 1 |0.5 |
|2021-01-01T00:00:24Z| 4 | 8  |
|2021-01-01T00:00:36Z| 9 |40.5|
|2021-01-01T00:00:48Z|16 |128 |

#### Output data

|\_value|
|-------|
|345.75 |

#### Related

* [cov() function](/flux/v0/stdlib/universe/cov/)

[transformations](/flux/v0/tags/transformations/)[aggregates](/flux/v0/tags/aggregates/)
| _time | x | y |
| --- | --- | --- |
| _time | x | y |
| 2021-01-01T00:00:00Z | 0 | 0 |
| 2021-01-01T00:00:12Z | 1 | 0.5 |
| 2021-01-01T00:00:24Z | 4 | 8 |
| 2021-01-01T00:00:36Z | 9 | 40.5 |
| 2021-01-01T00:00:48Z | 16 | 128 |

| _value |
| --- |
| _value |
| 345.75 |
