README.md (2058B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2020 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # incrnancount 22 23 > Compute a count incrementally, ignoring `NaN` values. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var incrnancount = require( '@stdlib/stats/incr/nancount' ); 31 ``` 32 33 #### incrnancount() 34 35 Returns an accumulator `function` which incrementally computes a count, ignoring `NaN` values. 36 37 ```javascript 38 var accumulator = incrnancount(); 39 ``` 40 41 #### accumulator( \[x] ) 42 43 If provided an input value `x`, the accumulator function returns an updated count. If not provided an input value `x`, the accumulator function returns the current count. 44 45 ```javascript 46 var accumulator = incrnancount(); 47 48 var count = accumulator( 2.0 ); 49 // returns 1 50 51 count = accumulator( 1.0 ); 52 // returns 2 53 54 count = accumulator( NaN ); 55 // returns 2 56 57 count = accumulator( 3.0 ); 58 // returns 3 59 60 count = accumulator(); 61 // returns 3 62 ``` 63 64 </section> 65 66 <!-- /.usage --> 67 68 <section class="examples"> 69 70 ## Examples 71 72 <!-- eslint no-undef: "error" --> 73 74 ```javascript 75 var randu = require( '@stdlib/random/base/randu' ); 76 var incrnancount = require( '@stdlib/stats/incr/nancount' ); 77 78 var accumulator; 79 var v; 80 var i; 81 82 // Initialize an accumulator: 83 accumulator = incrnancount(); 84 85 // For each simulated datum, update the count... 86 for ( i = 0; i < 100; i++ ) { 87 if ( randu() < 0.2 ) { 88 v = NaN; 89 } else { 90 v = randu() * 100.0; 91 } 92 accumulator( v ); 93 } 94 console.log( accumulator() ); 95 ``` 96 97 </section> 98 99 <!-- /.examples --> 100 101 <section class="links"> 102 103 </section> 104 105 <!-- /.links -->