if statement - If Else Inside For Loop in R -


i need create if/else statement in middle of loop in r.

i trying create hypothetical phase 1 clinical trial 3-3 design in r. start sample1 ~ binomial(3, x/10), x starting @ 1. if sample1 = 0, increase x 1 , take sample again. when sample1 > 0, take second sample, sample2 ~ binomial(3, x/10), @ same x value. if sample2=0, increase x, , take sample1 again. if sample2>0, print x value. want 10 times , see x value is. below code.

reps <- 10 mtd <- numeric(reps) (i in 1:reps) {   x <- 1   sample1 <- rbinom(1, 3, x/10)   if (sample1>0) {sample2 <- rbinom(1,3, x/10)   if (sample2>0) {mtd[i] <- (x)} else x<- x+1}   else x <-x+1   } mtd 

looking @ results, zeros not right. please assist. thanks.

maybe looking for:

reps <- 10 mtd <- numeric(reps) x <- 1 = 1 while (i < reps) {      sample1 <- rbinom(1, 3, x/10)     if (sample1>0) {         sample2 <- rbinom(1,3, x/10)         if (sample2>0) {             mtd[i] <- (x)             = i+1             x = 1         } else {             x <- x+1         }     } else {         x <- x+1     } } mtd 

what these changes every i, keep taking sample1 , sample2 until sample1 > 0 , sample2 >0. loop change i+1 , x reset 1.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -