Skip to main content\(\newcommand{\N}{\mathbb N} \newcommand{\Z}{\mathbb Z} \newcommand{\Q}{\mathbb Q} \newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 9.3 Test your knowledge
Checkpoint 9.3.1.
According to the chapter, what is the primary purpose of writing a "function" in R?
To create a block of code that can be used over and over again without retyping it.
Right! A function is a reusable piece of code designed to perform a specific task.
To automatically find and install packages that solve a problem.
No, packages contain functions, but the purpose of a function itself is reusability, not installation.
To define the statistical mode for a set of numbers.
No, this was the specific goal of the example function `MyMode`, but the general purpose of any function is to be a reusable block of code.
To pass an argument from one part of a program to another.
No, passing an argument is how you provide input *to* a function, but itβs not the primary purpose *of* the function.
Checkpoint 9.3.2.
When creating a function in R with the line
MyMode <- function(myVector)
, what is the role of
myVector
?
It is an "argument" that serves as a placeholder for the input data the function will use.
Correct! The text identifies this as the argument, or input, to the function.
It is the "return" value that the function sends back when it is finished.
No, the `return()` statement specifies the output. The argument is the input.
It is the name of the new function being created.
No, in this example, the name of the function is `MyMode`.
It is a new variable that is created in the R environment automatically.
No, it is a placeholder that only has meaning inside the function when the function is run.
You have attempted
of
activities on this page.