# How to calculate the statistics/ percentile in julia

**URL:** <https://discourse.julialang.org/t/how-to-calculate-the-statistics-percentile-in-julia/99580>\
**Category:** General Usage\
**Created:** [May 29, 2023, 10:47pm UTC](https://discourse.julialang.org/t/how-to-calculate-the-statistics-percentile-in-julia/99580 "2023-05-29T22:47:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RDuarte](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@RDuarte](https://discourse.julialang.org/u/RDuarte)\
**Post date:** [May 29, 2023, 10:47pm UTC](https://discourse.julialang.org/t/how-to-calculate-the-statistics-percentile-in-julia/99580/1 "2023-05-29T22:47:45Z")

</div>

Hello,

I’m new in Julia and I would like to do some statistics.  
How can I calculate a percentile of a matrix?  
I installed the using StatsBase package and I’m doing:  
percentile(mymatrix, 25), however I get an error

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [May 29, 2023, 11:01pm UTC](https://discourse.julialang.org/t/how-to-calculate-the-statistics-percentile-in-julia/99580/2 "2023-05-29T23:01:40Z")

</div>

Try

```julia
percentile(vec(mymatrix), 25)

```

as `mymatrix` is 2D and `percentile` expects a 1D vector. The `vec(...)` operation should not incur any performance penalty.

---

<div class="post-metadata">

**Author:** ![RDuarte](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@RDuarte](https://discourse.julialang.org/u/RDuarte)\
**Post date:** [May 29, 2023, 11:08pm UTC](https://discourse.julialang.org/t/how-to-calculate-the-statistics-percentile-in-julia/99580/3 "2023-05-29T23:08:27Z")

</div>

Hello,  
I think that this is not what I want.  
This returns only a single value, and what I want to obtain is the percentile of the complete matrix. In fact what I’m searching is the equivalent of matlab function “prcntile”  
Thank you in advance.

---

<div class="post-metadata">

**Author:** ![Norman](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@Norman](https://discourse.julialang.org/u/Norman)\
**Post date:** [May 29, 2023, 11:38pm UTC](https://discourse.julialang.org/t/how-to-calculate-the-statistics-percentile-in-julia/99580/4 "2023-05-29T23:38:24Z")

</div>

The way how the question is posted is somewhat ambiguous, because the meaning of “a percentile of a matrix” depends on how the values stored inside the matrix are interpreted.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [May 29, 2023, 11:39pm UTC](https://discourse.julialang.org/t/how-to-calculate-the-statistics-percentile-in-julia/99580/5 "2023-05-29T23:39:49Z")

</div>

That would be `percentile.(eachcol(mymatrix), 25)`. the key thing to realize here is that in Julia unlike Matlab, a `Matrix` and a list of lists are fairly different.

---

<div class="post-metadata">

**Author:** ![RDuarte](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@RDuarte](https://discourse.julialang.org/u/RDuarte)\
**Post date:** [May 29, 2023, 11:52pm UTC](https://discourse.julialang.org/t/how-to-calculate-the-statistics-percentile-in-julia/99580/6 "2023-05-29T23:52:48Z")

</div>

> [@Oscar\_Smith](#):
>
> `percentile.(eachcol(mymatrix), 25)`

Thank you Oscar, this worked for me!
