MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / mean

Function mean

inst/include/Rcpp/algorithm.h:391–414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

389// for REALSXP
390template< typename InputIterator >
391typename traits::enable_if< helpers::decays_to_ctype< typename std::iterator_traits< InputIterator >::value_type >::value
392 && traits::same_type< typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type, double >::value, double >::type
393 mean(InputIterator begin, InputIterator end)
394{
395 if (begin != end)
396 {
397 std::size_t n = end - begin;
398 long double s = std::accumulate(begin, end, 0.0L);
399 s /= n;
400
401 if (R_FINITE((double) s)) {
402 long double t = 0.0L;
403 while (begin != end) {
404 t += *begin++ - s;
405 }
406
407 s += t / n;
408 }
409
410 return (double) s;
411 }
412
413 return helpers::rtype< double >::NA();
414}
415
416// for LGLSXP and INTSXP
417template< typename InputIterator >

Callers 7

meanTestFunction · 0.50
meanTest_intFunction · 0.50
meanTest_logicalFunction · 0.50
meanIntegerFunction · 0.50
meanNumericFunction · 0.50
meanLogicalFunction · 0.50
meanComplexFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected