setting upper and lower limits in rnorm

前端 未结 5 1340
自闭症患者
自闭症患者 2020-12-03 14:04

I am simulating data using rnorm, but I need to set an upper and lower limit, does anyone know how to do this?

code:

rnorm(n = 10, mean = 39.74, sd =         


        
5条回答
  •  温柔的废话
    2020-12-03 14:56

    Assuming you want exactly 10 numbers and not the subset of them that is >0, <340 (and night not be a normal distribution):

        aa <- rnorm(n = 10, mean = 39.74, s = 25.09)
    
        while(any(aa<0 | aa>340)) { aa <- rnorm(n = 10, mean = 39.74, s = 25.09) }
    

提交回复
热议问题