Average Number of Days (Convert Type Day to Number?)

dates
#1

Hello Julia Community,

I have an array of elements of type Day, and when attempting to compute the mean of that array with mean(my_array_full_of_days), I get an InexactError because the result is a Float. Sum works just fine (as the return value is of type Day).

I tried converting the dates to Floats as well as simply rounding the return value of the sum function, but I get an error. Does anyone know what the cleanest solution to this problem is?

Thanks!!

1 Like
#2

This always happens to me, I found a (somewhat ugly) solution like 2 minutes after posting the question:

I can compute the mean manually by using Dates.value(sum(my_array_full_of_days)) / length(my_array_full_of_days)

It sure would be nice to be able to just do mean(my_array_full_of_days) !!

#3

How about mean(Dates.value.(my_array_full_of_days))?

4 Likes
#4

Awesome, I knew the awesome community here would come up with something better!

1 Like