# Compute the Covariance between Two Vectors in R Programming – cov() Function

`cov()` function in R Language is used to measure the covariance between two vectors.

Syntax: cov(x, y, method)

Parameters:
x, y: Data vectors
method: Type of method to be used

Example 1:

 `# Data vectors  ` `x <``-` `c(``1``, ``3``, ``5``, ``10``)  ` `   `  `y <``-` `c(``2``, ``4``, ``6``, ``20``)  ` `   `  `# Print covariance using Pearson method ` `print``(cov(x, y, method ``=` `"pearson"``))  `

Output:

``` 30.66667
```

Example 2:

 `# Data vectors  ` `x <``-` `c(``1``, ``3``, ``5``, ``10``)  ` `   `  `y <``-` `c(``2``, ``4``, ``6``, ``20``)  ` `   `  `# Print covariance using Pearson method ` `print``(cov(x, y, method ``=` `"kendall"``))  `

Output:

``` 12
```

Example 3:

 `# Data vectors  ` `x <``-` `c(``1``, ``3``, ``5``, ``10``)  ` `   `  `y <``-` `c(``2``, ``4``, ``6``, ``20``)  ` `   `  `# Print covariance using Pearson method ` `print``(cov(x, y, method ``=` `"spearman"``))  `

Output:

``` 1.666667
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.