Search code examples
r-exams

How to execute a statement only if a condition is met in R-exams


I intend the code to run only if c is different from a square less than 36, otherwise try again ...

c<-sample((1:36),1)
if(c==1|c==4|c==9|c==16|c==25|c==36){

}else{
  
}

Solution

  • Maybe a simplier condition:

    if (c %in% (1:5)^2) {...}