How to simulate data in RStudio?

I am very new to R. I've been trying to simulate some data for a hypothetical project. I want to simulate the results of a questionnaire. The data should be in a normal distribution but since the results are supposed to be between 1 to 5 (bc that is the scale of the questionnaire) I would like to set an interval when generating the data. I've been using rnorm but that doesn't work with an interval.
Does anyone know how to do this? I am not even sure if that is statistically possible so I would love some input if I am totally wrong here.
Thank you so much.

Something like this?

sample(1:5, size = 100, replace = TRUE, prob = c(0.10, 0.20, 0.40, 0.20, 0.10))
myrnorms <- rnorm(100000)

my_cutnorms <- cut(myrnorms,breaks = 5L)
my_cutnorms_nicelabels <- factor(my_cutnorms,labels=paste0("Q",1:5))

solution 3: :laughing:

# generate vector with normal distribution
v1 = rnorm(100) 

# scale the vector from 0 to 5, and round to full numbers
v2 = round(scales::rescale(v1, to=c(0,5)),0)

# show as histogram
hist(v2, breaks=5)

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