Variance in R (Example)

This article explains how to calculate the variance of numeric data with the var() function in the R programming language.

Example Data

my_values <- c(4, 1, 8, 5, 4, 4, 5, 6, 8, 1)      # Create example values

Computation of Sample Variance in R (var Function)

We can compute the variance of our example data with the var function:

var(my_values)                                    # Compute sample variance
# 5.642857

Note that the var function is computing the sample variance and not the population variance.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed