mardi 18 février 2020

R row-wise sampling with upside down normal distribution

I have a data frame DF that looks like this:

Min Max
10  80
20  90
40  120

I want to append a new Random column with a randomly generated number between the min and max values per row. The sampling of the number shall be derived from an upside down normal distribution and exclude the middle values like illustrated below

enter image description here

The below prototype code with single variables seem to work but I'm stuck with how to apply this row-wise.

min <- 1
max <- 20
q <- min + (max-min)*rbeta(10000, 0.5, 0.5)
q <- q[!(q > 5 & q < 15)][1:10000]
hist(q)

enter image description here




Aucun commentaire:

Enregistrer un commentaire