Skip to content

Commit

Permalink
Operation: add mode, median, coefficient of variation
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Dec 1, 2023
1 parent bb30874 commit 662bdb0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace exactextract {
f_out.set(m_field_names[0], stats.min().value_or(missing));
} else if (stat == "max") {
f_out.set(m_field_names[0], stats.max().value_or(missing));
} else if (stat == "majority") {
} else if (stat == "majority" || stat == "mode") {
f_out.set(m_field_names[0], stats.mode().value_or(missing));
} else if (stat == "minority") {
f_out.set(m_field_names[0], stats.minority().value_or(missing));
Expand All @@ -125,8 +125,10 @@ namespace exactextract {
f_out.set(m_field_names[0], stats.stdev());
} else if (stat == "variance") {
f_out.set(m_field_names[0], stats.variance());
} else if (stat == "coeffecient_of_variation") {
} else if (stat == "coefficient_of_variation") {
f_out.set(m_field_names[0], stats.coefficient_of_variation());
} else if (stat == "median") {
f_out.set(m_field_names[0], stats.quantile(0.5).value_or(std::numeric_limits<double>::quiet_NaN()));
} else if (stat == "quantile") {
for (std::size_t i = 0; i < m_quantiles.size(); i++) {
f_out.set(m_field_names[i], stats.quantile(m_quantiles[i]).value_or(std::numeric_limits<double>::quiet_NaN()));
Expand Down
2 changes: 1 addition & 1 deletion src/stats_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace exactextract {
}

static bool requires_stored_values(const std::string & stat) {
return stat == "mode" || stat == "minority" || stat == "majority" || stat == "variety" || stat == "quantile" || stat == "frac" || stat == "weighted_frac";
return stat == "mode" || stat == "minority" || stat == "majority" || stat == "variety" || stat == "quantile" || stat == "median" || stat == "frac" || stat == "weighted_frac";
}

template<typename T>
Expand Down

0 comments on commit 662bdb0

Please sign in to comment.