implemented countUnique aggregate function (issue#202)
@@ -20,6 +20,7 @@ import org.apache.commons.math3.stat.StatUtils;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import org.apache.commons.math3.stat.descriptive.moment.Kurtosis;
import org.apache.commons.math3.stat.descriptive.moment.Skewness;
+import tech.tablesaw.api.DoubleColumn;
import tech.tablesaw.api.NumberColumn;
/**
@@ -60,6 +61,22 @@ public class AggregateFunctions {
}
};
+ /**
+ * A function that calculates the count of the values in the column param
+ */
+ public static AggregateFunction countUnique = new Reduction("Count") {
+
+ @Override
+ public double agg(NumberColumn doubles) {
+ return doubles.unique().size();
+ }
+
+ @Override
+ public double agg(double[] data) {
+ return DoubleColumn.create("temp", data).unique().size();
+ }
+ };
+
/**
* A function that calculates the mean of the values in the column param
*/
