I need to create some data for a simulation. So I wanted to take a spreadsheet and, for each column, fill it with random data falling within a domain. A uniform distribution is good enough.
For a binary variable, I am currently doing following steps:
- create a formula like
if(rand()>0.5, "black", "white")
in a new column - fill a column with it, careful to only do it for the amount of rows I want (not just select the whole column and copy into it)
- copy the results and do
paste special -> values
in the original column
But if I have a variable with seven possible values, I can't think of anything better than seven nested if statements.
Are there better ways?
Best Answer
I think this is what you want. A spreadsheet the generates a column of rand() numbers. Then look up the rand() number and return another value.
In the following instruction be sure to keep the $s for absolute referencing.
=int(RAND()*$E$2)+1
(where cell E2 holds the upper limit of the random numbers).=vlookup(A2,$C$2:$D$8,2)
(where cells C2 to D8 hold the substitution values). If the random number generated is 1 then this returns the name Abe.