powered by
Draws from truncated univariate normal distribution within an interval.
rtnorm(mean, sd = 1, lower, upper, n = NULL)
Returns a vector of random numbers following the specified truncated univariate normal distribution.
vector of means. The length is the number of observations.
standard deviation. Defaults to 1.
a scalar of lower bound for truncation, or a vector of lower bounds with the same length as mean.
mean
a scalar of upper bound for truncation, or a vector of upper bounds with the same length as mean.
number of random samples when mean is a scalar.
set.seed(1203) x = rtnorm(mean=rep(1,1000), sd=2, lower=-2, upper=3) summary(x) # use the alternative form of input set.seed(1203) x = rtnorm(mean=1, sd=2, lower=-2, upper=3, n=1000) summary(x)
Run the code above in your browser using DataLab