Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

nanrange

Calculate the range of an array, ignoring NaN values.

The range is defined as the difference between the maximum and minimum values.

Usage

var nanrange = require( '@stdlib/stats/array/nanrange' );

nanrange( x )

Computes the range of an array, ignoring NaN values.

var x = [ 1.0, -2.0, NaN, 2.0 ];

var v = nanrange( x );
// returns 4.0

The function has the following parameters:

  • x: input array.

Notes

  • If provided an empty array, the function returns NaN.
  • The function supports array-like objects having getter and setter accessors for array element access (e.g., @stdlib/array/base/accessor).

Examples

var uniform = require( '@stdlib/random/base/uniform' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var nanrange = require( '@stdlib/stats/array/nanrange' );

function rand() {
    if ( bernoulli( 0.8 ) < 1 ) {
        return NaN;
    }
    return uniform( -50.0, 50.0 );
}

var x = filledarrayBy( 10, 'float64', rand );
console.log( x );

var v = nanrange( x );
console.log( v );