# How to efficiently get the DataFrame row index of statistical operation result

**URL:** <https://discourse.julialang.org/t/how-to-efficiently-get-the-dataframe-row-index-of-statistical-operation-result/60302>\
**Category:** New to Julia\
**Tags:** statistics, dataframes\
**Created:** [April 30, 2021, 11:30am UTC](https://discourse.julialang.org/t/how-to-efficiently-get-the-dataframe-row-index-of-statistical-operation-result/60302 "2021-04-30T11:30:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alessio](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@alessio](https://discourse.julialang.org/u/alessio)\
**Post date:** [April 30, 2021, 11:30am UTC](https://discourse.julialang.org/t/how-to-efficiently-get-the-dataframe-row-index-of-statistical-operation-result/60302/1 "2021-04-30T11:30:25Z")

</div>

Given a DataFrame like this:

```julia
df = DataFrame(A = 10*rand(10), B = 10*rand(10))
sort!(df, :A)
q1 = percentile(df.A, 25)

```

I would like to get the corresponding value in column `B` of the row such that `row.A` is the `A` value immediately greater than `q1`.

For example, in the sample below I’d like to get `2.81803`

```julia
10×2 DataFrame
 Row │ a b
     │ Float64 Float64
─────┼────────────────────
   1 │ 0.0734051 3.37658
   2 │ 2.54486 8.046
   3 │ 2.93121 1.538
   4 │ 3.17508 **2.81803**
   5 │ 3.6127 3.09565
   6 │ 3.83031 8.45346
   7 │ 4.73316 5.52375
   8 │ 7.01111 1.80292
   9 │ 8.60424 7.87036
  10 │ 8.68761 8.0496

```

I’d like to make this efficient and possibly avoid loops.

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [April 30, 2021, 12:08pm UTC](https://discourse.julialang.org/t/how-to-efficiently-get-the-dataframe-row-index-of-statistical-operation-result/60302/2 "2021-04-30T12:08:51Z")

</div>

You can use `df.B[searchsortedfirst(df.A, q1)]`.

I don’t know if there’s an implementation of `percentile` or `quantile` for sorted arrays that also returns the index…
