I need to create generate random variables based on a uniform distribution using the runif command. I have a column of values that the max and min will be based off. I was wondering if there is a way to apply the runif down the column without having to repeat the process for each value in the column of values? No others can be used. We're working with rnorm and runif, etc. so no other stats stuff allowed.
For example:
set.seed(1234)
values <- (30, 45, 80, 90, 80)
var_1 <- runif(5, 30*(.5), 30*(1.25))
var_2 <- runif(5, 45*(.5), 45*(1.25))
var_3 <- runif(5, 80*(.5), 80*(1.25))
var_4 <- runif(5, 90*(.5), 90*(1.25))
var_5 <- runif(5, 80*(.5), 80*(1.25))
This is basically what I'd have to do but only it's a larger data frame than just five observations. I also have to generate many more random numbers than just 5. I was hoping there was a way to expedite that process so I didn't need to repeat the var_3 <- runif part for every row in my datagram. If it helps, I can turn the column of the dataframe into a matrix with a single column and multiple rows. Eventually, I'll be sampling from these randomly generated numbers to perform a Monte Carlo simulation.
I'm assuming some apply function would work, but I'm still not certain how anything from the apply family works. I have looked into some already posted answer but the answers were a bit over my head and I couldn't change them to help me as I had initially thought I could.
Aucun commentaire:
Enregistrer un commentaire