In the previous exercise you wrote a function iq_classification
to classify iq scores into 2 classes. This function works perfect when we input a vector containing exactly one IQ-score:
iq_classification(135)
#> "Very superior"
iq_classification(c(120))
#> "Not very superior"
Note that when we input a vector containing more than one IQ-score this function throws a warning and returns only the classification name of the first value:
iq_classification(c(135, 120))
#> "Very superior"
#> Warning message:
#> the condition has length > 1 and only the first element will be used
This can be solved by using the ifelse
function istead of an if
-statement.
iq_classification
function using the ifelse
function istead of an if
-statement, this function takes one argument for the vector of IQ-score(s) and returns a vector with classification name(s) from the following table.IQ Range | IQ Classification |
---|---|
130 and above | "Very superior" |
129 and below | "Not very superior" |