# Sampling Groups and individual within the group

**URL:** <https://discourse.julialang.org/t/sampling-groups-and-individual-within-the-group/72199>\
**Category:** New to Julia\
**Tags:** dataframes, random, splitapplycombine\
**Created:** [November 28, 2021, 2:07pm UTC](https://discourse.julialang.org/t/sampling-groups-and-individual-within-the-group/72199 "2021-11-28T14:07:08Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 28, 2021, 2:45pm UTC](https://discourse.julialang.org/t/sampling-groups-and-individual-within-the-group/72199/4 "2021-11-28T14:45:16Z")

</div>

One way that outputs the result as a dataframe, inspired by [this post](https://discourse.julialang.org/t/how-to-sample-rows-from-a-dataframe/19782/2).

_(continuation of your code:)_

```julia
using StatsBase

ix2 = sample(1:length(gb), 2, replace=false)
db = vcat([gbi[sample(axes(gbi, 1), 2; replace=false), 1:3] for gbi in gb[ix2]]...)

 Row │ x1 x2 x3    
     │ Int64 Int64 Int64 
─────┼─────────────────────
   1 │ 1 2 4
   2 │ 5 6 7
   3 │ 1 3 4
   4 │ 1 2 3

```

---

_[View the full topic](https://discourse.julialang.org/t/sampling-groups-and-individual-within-the-group/72199)._
