liveBook · Manning

Return value

As explained in Statistics Slam Dunk

A return value is the output produced by a function after it runs.

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

How Statistics Slam Dunk covers it

How deep it goes
Defines return values and demonstrates explicit returns in custom functions, without descending into evaluation internals.
Examples
Demonstrates mean(), correlation conversion, and a Gini estimate with numeric outputs and a missing-argument error.
What it assumes
Teaches function names, arguments, bodies, and return values together rather than assuming those components.
What you can do after
Build it from scratch by writing R functions that calculate, return, and reuse derived values.
How it connects
Connects return values with functions, arguments, function bodies, and user-defined functions.

Also explained in

Compare how 8 books explain return value →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.