Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent to R's sample(x,y,prob=) in Julia

Tags:

julia

Julia-users: is there an equivalent to R's sample(x,y,prob=) to sample from a given set of values with weighted probabilities? The rand() function is equivalent to sample(x,y), but as far as I'm aware there's no option to add probability weights... Any help appreciated!

like image 453
ADMD Avatar asked Mar 13 '23 07:03

ADMD


1 Answers

OK - done a bit more digging and wsample from the Distributions package seems to be the answer:

using Distributions
wsample(population, weights, n)

Next time I'll look harder before posting!

like image 67
ADMD Avatar answered Mar 20 '23 08:03

ADMD