实例 R 语言 嵌套 if 语句

x
 
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.")
}
                    

输出结果

[1] "Above ten"
[1] "and also above 20!"