Sampling Groups and individual within the group

One way that outputs the result as a dataframe, inspired by this post.

(continuation of your code:)

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