Search code examples
rsample

Create sample vector data in R with a skewed distribution with limited range


I want to create in R a sample vector of data in R, in which I can control the range of values selected, so I think I want to use sample to limit the range of values generated rather than an rnorm-type command that generates a range of values based upon the type of distribution, variance, SD, etc.

So I'm looking to do a sample with a specified range (e.g. 1-5) for a skewed distribution something like this:

x=rexp(100,1/10)

Here's what I have but does not provide a skewed distribution:

y=sample(1:5,234, replace=T) 

How can I have my cake (limited range) and eat it too (skewed distribution), so to speak.

Thanks


Solution

  • set.seed(3)
    hist(sample(1:10, size = 100, replace = TRUE, prob = 10:1))
    

    enter image description here