varm
varm(v, m)
Compute the sample variance of a vector v
with known mean m
. Note: Julia does not ignore NaN
values in the computation.
Examples

Calculate sample variance with known mean:
julia> v = [1, 2, 3, 4, 5]; julia> m = 3.0; julia> varm(v, m) 2.5
This example calculates the sample variance of the vector
v
with a known meanm
of 3.0. 
Handle NaN values:
julia> v = [1.0, 2.0, NaN, 4.0, 5.0]; julia> m = 3.0; julia> varm(v, m) NaN
The
varm
function does not ignoreNaN
values in the computation. If the vectorv
containsNaN
values, the result will beNaN
.  Calculate variance with integer values:
julia> v = [10, 20, 30, 40, 50]; julia> m = 30.0; julia> varm(v, m) 200.0
The
varm
function can also be used with integer values. In this example, it calculates the variance of the vectorv
with a known meanm
of 30.0.
Common mistake example:
julia> v = [];
julia> m = 5.0;
julia> varm(v, m)
ERROR: DomainError with NaN result
In this example, the vector v
is empty, resulting in a DomainError
with a NaN
result. Ensure that the vector has at least one element before using the varm
function to avoid such errors.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.