R Nested If


Nested If Statements

You can also have if statements inside if statements, this is called nested if statements.

Example

x <- 41

if (x > 10) {
  print("Above ten")
  if (x > 20) {
    print("and also above 20!")
  } else {
    print("but not above 20.")
  }
} else {
  print("below 10.")
}
Try it Yourself »


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.