# Is it possible to access row index inside DataFramesMeta macros?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-access-row-index-inside-dataframesmeta-macros/87944>\
**Category:** General Usage\
**Tags:** dataframesmeta\
**Created:** [September 28, 2022, 5:21pm UTC](https://discourse.julialang.org/t/is-it-possible-to-access-row-index-inside-dataframesmeta-macros/87944 "2022-09-28T17:21:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dispeduspo](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@dispeduspo](https://discourse.julialang.org/u/dispeduspo)\
**Post date:** [September 28, 2022, 5:21pm UTC](https://discourse.julialang.org/t/is-it-possible-to-access-row-index-inside-dataframesmeta-macros/87944/1 "2022-09-28T17:21:19Z")

</div>

Is there a way to access **current\_row\_index** in the following snippet ?

```julia
@with df begin
    fn.(:col, current_row_index)
end

```

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [September 28, 2022, 5:41pm UTC](https://discourse.julialang.org/t/is-it-possible-to-access-row-index-inside-dataframesmeta-macros/87944/2 "2022-09-28T17:41:11Z")

</div>

No, unfortunately that is not possible. You would have to create a column storing the row number to do this.

`@eachrow` and `@eachrow!` allow the use of the row index, but they have different behavior than `@with`.

---

<div class="post-metadata">

**Author:** ![dispeduspo](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@dispeduspo](https://discourse.julialang.org/u/dispeduspo)\
**Post date:** [September 29, 2022, 10:08am UTC](https://discourse.julialang.org/t/is-it-possible-to-access-row-index-inside-dataframesmeta-macros/87944/3 "2022-09-29T10:08:55Z")

</div>

There’s a solution [julia - Is it possible to access row index inside DataFramesMeta macros? - Stack Overflow](https://stackoverflow.com/questions/73885594/is-it-possible-to-access-row-index-inside-dataframesmeta-macros)

```julia
julia> using DataFramesMeta

julia> fn(x, y) = (x, y)
fn (generic function with 1 method)

julia> df = DataFrame(col=["a", "b", "c"])
3×1 DataFrame
 Row │ col
     │ String
─────┼────────
   1 │ a
   2 │ b
   3 │ c

julia> @with df begin
           fn.(:col, axes(df, 1))
       end
3-element Vector{Tuple{String, Int64}}:
 ("a", 1)
 ("b", 2)
 ("c", 3)

```
