# How to obtain the number of rows in each group using DataFramesMeta?

**URL:** https://discourse.julialang.org/t/how-to-obtain-the-number-of-rows-in-each-group-using-dataframesmeta/21955
**Category:** Data
**Tags:** first-steps
**Created:** [March 17, 2019, 5:30am UTC](https://discourse.julialang.org/t/how-to-obtain-the-number-of-rows-in-each-group-using-dataframesmeta/21955 "2019-03-17T05:30:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [March 17, 2019, 5:30am UTC](https://discourse.julialang.org/t/how-to-obtain-the-number-of-rows-in-each-group-using-dataframesmeta/21955/1 "2019-03-17T05:30:55Z")

</div>

```julia
using DataFrames, DataFramesMeta

a = DataFrame(a = rand(1:10, 100))

@> begin
   a
   @by(:a, count = length(:a))
end

```

is there a more convenient function like R’s `dplyr::n()` which returns the number of rows? Or even, R’s `data.table`’s `.N`?

---

<div class="post-metadata">

### Author: ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)
#### Post date: [March 17, 2019, 5:58am UTC](https://discourse.julialang.org/t/how-to-obtain-the-number-of-rows-in-each-group-using-dataframesmeta/21955/2 "2019-03-17T05:58:02Z")

</div>

How about:

```julia
by(a, :a, nrow)

```

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [March 17, 2019, 6:50am UTC](https://discourse.julialang.org/t/how-to-obtain-the-number-of-rows-in-each-group-using-dataframesmeta/21955/3 "2019-03-17T06:50:16Z")

</div>

Hoping to use DataFramesMeta code.
