Hey,
I'm a beginner in R
I created the following dateframe (just an example, the real data frame contains +2000 rows):
RowNum <-c(1:5)
Prob <- c(0.5,0.3,0.8,0.2,0.9)
Attempts <- c(rep(0,5))
Succeeded <- c(rep(0,5))
Overall <- data.frame(RowNum,Prob,Attempts,Succeeded)
I want to create the following:
Creating random number (between 0-1) ->
A. If the random number is lower than the prob in the first row -> add 1 to Attempts and 1 to Succeeded (just for the first row) and then create another random number and move to the next row and check if is greater or lower - if is lower, add 1 to Attempts and 1 to Succeeded (just for the second row) and then create another random number and move to the next row...and so on...
B. If the random number is greater than the prob in the first row -> add 1 only to Attempts (just for the first row) and then create another random number and do the same but don't continue to the next row.
It's like creating a counter for each element in the vector, and to calculation should move to the next row only when the random number is lower than the prob.
Thanks for your help!