using StatsBase
using SplitApplyCombine
using DataPipes
@p begin
splitdimsview(a, 1)
group(_[4])
collect()
sample(โ, 2; replace=false) # choose two groups
map(sample(_, 2; replace=false)) # choose two members from each
end
Hi, Out of three groups; 1, 2, 3 ; I want two randomly selected groups. And within these two groups I want two randomly selected elements from three elements. The final output must look similar to below
@p begin
splitdims(a, 1)
group(_[4])
collect()
sample(โ, 2; replace=false)
map(sample(_, 2; replace=false))
mapmany(_, __[1:3])
combinedims()
permutedims()
end
However, note that itโs often easier to work with data when each โindividualโ (e.g., group member in your case) is separate. Eg, vector-of-vectors vs matrix.