Psst! Check what courses we have in our offer, and get them all here to save $727. Act fast–this deal is available only 3/14–3/21.
Text values
20. Function result as a variable


Cool! As you may have already guessed, the result returned by a function can be assigned to a variable for use in further calculations.

For example, the result of round(182.5) can be saved in a variable named height, like so:

height <- round(182.5)

Just as before, assignment relies on the assignment operator (<-). When we type height later on in the editor, R will return the value 182 — the result of the earlier function call round(182.5).


Round John's current weight of 87.3 kilograms, and store it in a variable named weight.