-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
Description
Using the std() or variance() functions on an array of values with units assigned results in an error. This seems to be in contrast to every other function in the Statistics category (mean(), median(), mad(), etc), which seem to operate happily on arrays of unit'ed values.
I'm not sure if this is a bug or a feature request, but I'd like to request that support for unit'ed values be added to the std() and variance() functions.
Example of error
vals = [2 mm, 5 mm, 6 mm]
math.mean(vals)
// 4.3333333333333 mm
math.std(vals)
// TypeError: Cannot calculate std, unexpected type of argument (type: Unit, value: {"mathjs":"Unit","value":2,"unit":"in","fixPrefix":false})I note, however, that I can write a simple function with map() that calculates the standard deviation of this array without difficulty:
math.sqrt(math.sum(math.map(vals, f(x) = (x-mean(vals))^2))/math.size(vals)[1])
// 1.6996731711976 mmReactions are currently unavailable
