How to generate ramdom list with certain qualities (Numbers/integers, a certain mean, min, max)?

I need to create a data set of 100 numbers with a min of 0 an max of 10, a mean of 5 that is normally distributed.

Any help on this? Thank you so much!

Would be great if I could do the same thing with integers as well.

Thanks in advance.

How closely do you want to match the mean of 5? Here is one way to get close but not exactly 5.

set.seed(1)
DAT <- rnorm(98, mean = 5, sd = 5/3)
range(DAT)
#> [1] 1.308834 9.002696
mean(DAT)
#> [1] 5.21406
DAT <- c(DAT, 0, 10)
range(DAT)
#> [1]  0 10
mean(DAT)
#> [1] 5.209779
qqnorm(DAT)

shapiro.test(DAT)
#> 
#>  Shapiro-Wilk normality test
#> 
#> data:  DAT
#> W = 0.98965, p-value = 0.6364

Created on 2021-02-24 by the reprex package (v0.3.0)

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.