# filtered_mean (Descriptive Statistics) 1.x.x.x

### Import

#include <archr/stats/filtered_mean.h>
#include <archr/stats/filtered_mean.hpp>
import archr.stats
atomsLoads('archr')

### Synopsis

  float archr_stats_filtered_mean_f32(const float *first, size_t nbelem);  (1)  double archr_stats_filtered_mean_f64(const double *first, size_t nbelem);  (2)
  float filtered_mean(const float *first, size_t nbelem);  (1)  double filtered_mean(const double *first, size_t nbelem);  (2)  float filtered_mean(const float *first, const float *last);  (3)  double filtered_mean(const double *first, const double *last);  (4) template typename Range::value_type filtered_mean(const Range& data);  (5)
 subroutine archr_stats_filtered_mean_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem)  (1) subroutine archr_stats_filtered_mean_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem)  (2)
 def filtered_mean(first): return r  (1)
 function r = archr_stats_filtered_mean(first)  (1)

### Description

This function computes the filtered mean (or average) of the elements stored in:

• (1,2) the [first, last[ range
• (3,4) the [first, first+nbelem[ range

### Parameters

 first the beginning of the range of elements to average. last the end of the range of elements to average. nbelem the number of elements to average.

### Return value

The average of the elements in the given range or container in which any NaN elements are ignored.

### Example

#include <archr/stats/filtered_mean.h>
#include <stdio.h>

int main()
{
float fnan = 0.f/0.f;
float v[] = {1,fnan,3,4,fnan,6};

printf("filtered_mean(1,NaN,3,4,NaN,6) = %f\n", archr_stats_filtered_mean_f32(&v[0],6) );

return 0;
}


### Possible Output

filtered_mean(1,NaN,3,4,NaN,6) = 3.500000
filtered_mean(1,NaN,3,4)       = 2.666667

#include <archr/stats/filtered_mean.hpp>
#include <iostream>
#include <vector>

int main()
{
float fnan = 0.f/0.f;
std::vector<float> v{1,fnan,3,4,fnan,6};

std::cout << "filtered_mean(1,NaN,3,4,NaN,6) = " << archr::stats::filtered_mean(v) << "\n";
std::cout << "filtered_mean(1,NaN,3,4,NaN)   = " << archr::stats::filtered_mean(v.data(), 5) << "\n";
std::cout << "filtered_mean(1,NaN,3,4)       = " << archr::stats::filtered_mean(v.data(), v.data() + 4) << "\n";

return 0;
}


### Possible Output

filtered_mean(1,NaN,3,4,NaN,6) = 3.5
filtered_mean(1,NaN,3,4,NaN)   = 2.66667
filtered_mean(1,NaN,3,4)       = 2.66667