# Applying \`quantile\` to \`AbstractArray\`s

**URL:** <https://discourse.julialang.org/t/applying-quantile-to-abstractarray-s/20619>\
**Category:** Statistics\
**Tags:** statistics\
**Created:** [February 9, 2019, 11:21pm UTC](https://discourse.julialang.org/t/applying-quantile-to-abstractarray-s/20619 "2019-02-09T23:21:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [February 9, 2019, 11:21pm UTC](https://discourse.julialang.org/t/applying-quantile-to-abstractarray-s/20619/1 "2019-02-09T23:21:05Z")

</div>

The docstring of `quantile` in the `Statistics` module says:

> ```julia
> quantile(itr, p; sorted=false)
> 
> ```
> 
> Compute the quantile(s) of a collection `itr` at a specified probability or vector or tuple of  
> probabilities `p` on the interval [0,1]. The keyword argument `sorted` indicates whether  
> `itr` can be assumed to be sorted.

But `itr` cannot actually be any iterable; only `<:AbstractVector` or something that becomes that type after `collect`, as seen in the “in-place” function `quantile!` For instance, a `Matrix` or more generally an `AbstractArray{T,N}` where `N > 1` is not accepted.

What would be the best way to calculate quantiles for such variables?

An obvious option is `quantile(x[:], p)`, but this makes an unnecessary copy.

`quantile(view(x,:), p)` would avoid the copy, but I don’t know if there something better.

---

<div class="post-metadata">

**Author:** ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Post date:** [February 10, 2019, 12:11am UTC](https://discourse.julialang.org/t/applying-quantile-to-abstractarray-s/20619/2 "2019-02-10T00:11:35Z")

</div>

Probably best to submit a PR for supporting an iterable version. Currently, I guess

```julia
quantile(vec(x), p)

```
