Else if 2.0
You can do anything you want inside if-else constructs. You can even put in another set of conditional statements. Examine the following code chunk:
if (number < 10) {
if (number < 5) {
result <- "extra small"
} else {
result <- "small"
}
} else if (number < 100) {
result <- "medium"
} else {
result <- "large"
}
print(result)
Have a look at the following statements:
- If
number
is set to 6, "small" gets printed to the console. - If
number
is set to 100, R prints out "medium". - If
number
is set to 4, "extra small" gets printed out to the console. - If
number
is set to 2500, R will generate an error, asresult
will not be defined.
Select the option that lists all the true statements.
This exercise is part of the course
Intermediate R
Hands-on interactive exercise
Turn theory into action with one of our interactive exercises
