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
xnoryhave default values. - FALSE: The
xargument 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
returnstatement is misused; it should return the squared vector directly. - FALSE: The function uses an undefined variable
vinstead of the argumentx. - 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).