0
0
R Programmingprogramming~5 mins

Return values in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a return value in R functions?
A return value is the result that a function sends back after it finishes running. It is what you get when you call the function.
Click to reveal answer
beginner
How do you explicitly return a value from a function in R?
You use the return() function inside your function to send back a specific value.
Click to reveal answer
beginner
What happens if you do not use return() in an R function?
R automatically returns the last evaluated expression in the function, even if you don't use return().
Click to reveal answer
intermediate
Can a function in R return multiple values?
Yes, by returning a list or other data structure, a function can return multiple values at once.
Click to reveal answer
beginner
What is the difference between print() and returning a value in R?
print() shows output on the screen but does not send a value back from the function. Returning a value allows other code to use that result.
Click to reveal answer
What does the return() function do in R?
ASends a value back from a function
BPrints a value to the console
CStops the entire program
DCreates a new variable
If a function in R does not have a return() statement, what happens?
AThe function returns the last evaluated expression
BThe function returns NULL
CThe function causes an error
DThe function returns TRUE
How can a function return multiple values in R?
ABy using global variables
BBy using multiple <code>return()</code> statements
CBy printing all values
DBy returning a list containing all values
Which of these is NOT true about return values in R?
AReturn values can be used in other parts of the program
BReturn values are always printed automatically
CReturn values come from functions
DReturn values can be any type of data
What is the main difference between print() and returning a value?
A<code>print()</code> sends a value back, return shows output
BThey do the same thing
C<code>print()</code> shows output, return sends a value back
DNeither can be used in functions
Explain what a return value is in R and how it is used in functions.
Think about what happens after a function finishes running.
You got /3 concepts.
    Describe how you can return multiple values from a single R function.
    Consider how to package several things together.
    You got /3 concepts.