Solution Review: Returning from a Function
Understand how to write R functions that iterate over integer vectors and return results such as labeling numbers even or odd. This lesson helps you master returning values from functions, updating output dynamically, and applying these skills for effective data processing in R.
We'll cover the following...
We'll cover the following...
Solution: Returning from a Function
Explanation
The input to the function is an integer vector testVariable. We iterate over the entire vector. Then side by side populate the output vector that stores the result - even or odd for all the elements of the input vector. Later, we return the output vector.
Remember,
output <- c(output, "even")is updating the variableoutputby appending an entry to the previous value of the variableoutput.