mitchelloharawild / distributional

Vectorised distributions for R
https://pkg.mitchelloharawild.com/distributional
GNU General Public License v3.0
94 stars 15 forks source link

add implementation of median.dist_default() #58

Closed mjskay closed 3 years ago

mjskay commented 3 years ago

I ran into a bit of unexpected behavior when making some updates to ggdist. Currently without an implementation of median.dist_default() you can get some errors when trying to get medians of slices of distributions:

> x = dist_normal(1,1)
> median(x)
[1] 1
> x[[1]]
N(1, 1)
> median(x[[1]])
Error in rank(x, ties.method = "min", na.last = "keep") : 
  unimplemented type 'list' in 'greater'

This PR adds an implementation of median.dist_default() that simply copies the implementation of median.distribution() so that the following works:

> x = dist_normal(1,1)
> median(x)
[1] 1
> median(x[[1]])
[1] 1

Happy to adjust as needed.

mitchelloharawild commented 3 years ago

Looks good, thanks. I'll start working toward a release to include these changes.

mjskay commented 3 years ago

Thanks, much appreciated!