user2032717 - 4 months ago 51

R Question

How can I generate a positive random number list with specified mean and SD?

I know how to do it with rnorm in R but it is not positive since it sampled from a normal distribution, if I'm right.

My preferred language is matlab but a script in R is Ok too.

thanks.

Answer

It really depends on the underlying distribution.

With `R = normrnd(mu,sigma)`

you can generate normal distributed random numbers with specified mean and standard deviation.

`R = lognrnd(mu,sigma)`

generates lognormal distributed random numbers.

You can also take a look at this where you can specify the distribution.

Just make sure that you check if it really is positive, e.g.

```
mu = 10;
sigma = 1;
R = normrnd(mu,sigma,1,500);
%R(R<=0) = resample
```