Skip to contents

Calculate correlations and variances, including when x or y is an rvec.

Usage

var(x, y = NULL, na.rm = FALSE, use)

Arguments

x

A numeric vector, matrix, data frame, or rvec().

y

NULL (default) or a vector, matrix, data frame, or rvec with compatible dimensions to x.

na.rm

Whether NAs removed before calculations.

use

Calculation method. See stats::var().

Value

An rvec, if x or y is an rvec. Otherwise typically a numeric vector or matrix.

Details

To enable different behavior for rvecs and for ordinary vectors, the base R function stats::var() is turned into a generic, with stats::var() as the default.

For details on the calculations, see the documentation for stats::var().

See also

Examples

x <- rvec(cbind(rnorm(10), rnorm(10, sd = 20)))
x
#> <rvec_dbl<2>[10]>
#>  [1] 0.3911,23.47   -1.368,7.938   1.223,6.036    0.2707,5.42    -1.769,11.94  
#>  [6] -1.037,-5.76   1.553,-10.98   0.3615,4.56    -0.07135,20.84 0.8971,20.19  
var(x)
#> <rvec_dbl<2>[1]>
#> [1] 1.237,126.5