Skip to content

Commit

Permalink
calculate stats correctly for datetime type values
Browse files Browse the repository at this point in the history
  • Loading branch information
willium committed Apr 10, 2019
1 parent f197591 commit 81748ec
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 81748ec

Please sign in to comment.