Generating/Simulating Random Data

Dear all,

I have a question regarding simulating data in r with which I am having some trouble.

I am trying to simulate/generate data for only 1 variable on 1000 hypothetical study respondents.

The only parameters for the data is that the distribution should more or less follow a normal one, and that the obtainable values of the variable are between 1 and 5 and are only whole numbers (1,2,3,4,5).

I thought that this would be a fairly easy task, but since I am a novice in r I have hit a wall with my progress, and honestly, there hasn't been much progress.

I really the solution is as easy as it seems to me.

Additionally, if anyone has any suggestion on how to simulate assymetric or even bimodal data between values 1 and 5, it would be greatly appreciated.

Kind regards and thank you very much in advance if you decide to help!

As I'm sure you understand, you can't have a normal distribution limited to 5 integers. So I'll assume you want something that just kind of looks like points on a normal. The trick is to pick weights that give the heights you want and to then use sample(). For example,

weights <- dnorm(1:5,mean = 3)
randomDraws <- sample(1:5, size = 1000, replace = TRUE, prob = weights)
3 Likes

Thank you for the elegant and simple solution!

This topic was automatically closed 7 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.