My data set currently looks like this:
Contract number FA NAAR q
CM300 9746 47000 0.5010
UL350 80000 0 0.01234
RAD3421 50000 10000 0.9431
I would like to add a column with a randomly generated number (called trial) between 0-1 for each row, and compare this number to the value in column q with another column saying 'l' if q < trial, and 'd' if q > trial.
This is my code which accomplishes this task one time.
trial <- runif(3, min = 0, max = 1)
data2 <- mutate(data, trial)
data2 <- mutate(data, qresult = ifelse(data2$q <= data2$trial, 'l', 'd'))
My struggle is to get this to repeat for several trials , adding new columns onto the table with each repetition. I have tried several types of loops, and looked through several questions and cannot seem to figure it out. I am fairly new to R, so any help would be appreciated!