A return value is the output produced when a function runs. Calling mean() on a continuous variable, for example, returns a numeric average. section 13.7
A function’s return value fits into its broader structure:
- Arguments provide inputs, the function body performs the operation, and the return value supplies the output. section 13.7
- User-defined functions can explicitly return calculated results, just like built-in functions. section 13.7
Converting a correlation
The function r_to_rsquared() squares its input and returns the result. Calling r_to_rsquared(.42) produces 0.1764; a reverse function returns .42 from .1764. section 13.7
r_to_rsquared <- function(r) {
rsquared <- r^2
return(rsquared)
}
The R definition shows the calculated value being assigned and explicitly returned. section 13.7







