Calculate the mid-range of an array, ignoring
NaNvalues.
The mid-range is defined as the arithmetic mean of the maximum and minimum values in a data set. The measure is the midpoint of the range and a measure of central tendency.
var nanmidrange = require( '@stdlib/stats/array/nanmidrange' );Computes the mid-range of an array, ignoring NaN values.
var x = [ 1.0, -2.0, NaN, 2.0 ];
var v = nanmidrange( x );
// returns 0.0The function has the following parameters:
- x: input array.
- 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).
var uniform = require( '@stdlib/random/base/uniform' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var nanmidrange = require( '@stdlib/stats/array/nanmidrange' );
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 = nanmidrange( x );
console.log( v );