Complete the code to create an anonymous function that adds 5 to its input.
add_five <- function(x) [1] x + 5 add_five(10)
The anonymous function must take one argument x and add 5 to it.
Complete the code to apply an anonymous function that squares each element in the vector.
squared <- sapply(c(1, 2, 3), [1](x) x^2) squared
The anonymous function must take one argument x and return its square.
Fix the error in the anonymous function that multiplies input by 3.
triple <- [1](x) x * 3 triple(4)
The correct syntax to define an anonymous function is function(x).
Fill both blanks to create an anonymous function that returns TRUE if input is greater than 10.
check_gt_10 <- [1](x) x [2] 10 check_gt_10(15)
if instead of function to define the functionThe function keyword defines the anonymous function, and the operator > checks if x is greater than 10.
Fill all three blanks to create a list of squares for numbers greater than 3 using an anonymous function.
result <- lapply(1:5, [1](num) if (num [2] 3) [3] num^2 else NULL) result
if instead of function to define the function< instead of > for comparisonreturn keywordThe anonymous function is defined with function, uses > to check if the number is greater than 3, and return to output the square.