R if-else Control

Program control if-else in R is similar to other programming language. The flow of program is decide by a logical “if condition”. Programmer decide the program flow when condition result a “true” or “false”.


if a > 10 {
  b <- 10
} else {
  b <- 100

}

b <- if (a > 10){
10
} else {
  100
}

When value of “a” bigger than 10, then assign 10 to variable b otherwise assign 100.

Video