Knowledge Quiz: Tutorial 2

Note
  • Click the check-mark button to check your answer.
  • Click the question-mark button to see an explanation of the solution.

Which function definition includes a default argument?

  • FALSE: This is not a valid function definition.
  • FALSE: This is not a valid function definition.
  • FALSE: Neither x nor y have default values.
  • FALSE: The x argument has no default value.
  • FALSE: This is not a valid function definition.

Which function correctly squares each element of a vector v?

  • FALSE: The function lacks an argument to accept the vector v.
  • FALSE: This function prints squared values but does not return a vector of squared elements.
  • FALSE: The return statement is misused; it should return the squared vector directly.
  • FALSE: The function uses an undefined variable v instead of the argument x.
  • TRUE: This function correctly squares each element of vector v.

This function is supposed to return the cube of x, but there is something wrong with it. Fix the body of the function so that it correctly returns the cube of x.

{. .cell-code} cube <- function(x) { print(x^3) }

The issue with the function is that it uses print() instead of return(). To fix it, we should replace print(x^3) with return(x^3).

Back to top