dimanche 26 février 2023

Sampling from uniform distribution row wise

Consider the following data:

df <- data.frame(id=1:5,
                 x_min = c(0.1,0.2,0.3,0.4,0.5),
                 x_max = c(0.15,0.23,0.38,0.44,0.57))

I intend to draw a random sample from a uniform distribution for each row. Why I'm getting the same values for column y? Here is what I did:

set.seed(12)
df$y <- runif(1, min=df$x_min, max=df$x_max)

Output:

> df
  id x_min x_max        y
1  1   0.1  0.15 0.103468
2  2   0.2  0.23 0.103468
3  3   0.3  0.38 0.103468
4  4   0.4  0.44 0.103468
5  5   0.5  0.57 0.103468



Aucun commentaire:

Enregistrer un commentaire