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

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

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) !!

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

4 Likes

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

1 Like