From 81748ecbbaa3fee6e4eecfb740f96b202a400152 Mon Sep 17 00:00:00 2001 From: Will Strimling Date: Tue, 9 Apr 2019 21:53:11 -0700 Subject: [PATCH] calculate stats correctly for datetime type values --- src/stats.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/stats.js b/src/stats.js index ec8bf68..0af6159 100644 --- a/src/stats.js +++ b/src/stats.js @@ -656,13 +656,17 @@ stats.mutual.dist = function(values, a, b, counts) { // Compute a profile of summary statistics for a variable. stats.profile = function(values, f) { var mean = 0, + median = 0, valid = 0, missing = 0, distinct = 0, min = null, max = null, + q1 = 0, + q3 = 0, M2 = 0, vals = [], + t = type(values, f), u = {}, delta, sd, i, v, x; // compute summary stats @@ -676,7 +680,7 @@ stats.profile = function(values, f) { ++missing; } else if (util.isValid(v)) { // update stats - x = (typeof v === 'string') ? v.length : v; + x = (t === 'date') ? (new Date(v)).getTime() : (typeof v === 'string') ? v.length : v; if (min===null || x < min) min = x; if (max===null || x > max) max = x; delta = x - mean; @@ -692,7 +696,7 @@ stats.profile = function(values, f) { vals.sort(util.cmp); return { - type: type(values, f), + type: t, unique: u, count: values.length, valid: valid,