describe method
Computes summary statistics for numeric columns. Returns a map mapping each numeric column to a map of count, sum, mean, min, and max.
Implementation
Map<String, Map<String, num>> describe() {
Map<String, Map<String, num>> summary = {};
for (int i = 0; i < columns.length; i++) {
String col = columns[i];
List<num> numericValues = [];
for (var row in rows) {
var value = row[i];
if (value is num) numericValues.add(value);
}
if (numericValues.isNotEmpty) {
num total = numericValues.reduce((a, b) => a + b);
num mean = total / numericValues.length;
num min = numericValues.reduce((a, b) => a < b ? a : b);
num max = numericValues.reduce((a, b) => a > b ? a : b);
summary[col] = {
'count': numericValues.length,
'sum': total,
'mean': mean,
'min': min,
'max': max,
};
}
}
return summary;
}