Else if 2.0
if-else 構文の中には、あらゆる処理を書くことができます。別の条件文をネストすることも可能です。次のコードチャンクを確認しましょう。
if (number < 10) {
if (number < 5) {
result <- "extra small"
} else {
result <- "small"
}
} else if (number < 100) {
result <- "medium"
} else {
result <- "large"
}
print(result)
以下の文をよく読んでください。
numberが 6 のとき、コンソールに "small" が出力されます。numberが 100 のとき、R は "medium" を出力します。numberが 4 のとき、コンソールに "extra small" が出力されます。numberが 2500 のとき、resultが定義されないためエラーが発生します。
すべて正しい文の組み合わせを選んでください。
この演習はコースの一部です
