Complete the code to define a function with a default argument value.
greet <- function(name = [1]) { paste("Hello", name) }
The default value for the argument name should be a string, so it must be enclosed in quotes.
Complete the code to call the function without providing the argument, so it uses the default value.
greet([1])Calling the function without any argument uses the default value.
Fix the error in the function definition by completing the default argument value correctly.
multiply <- function(x, y = [1]) {
x * y
}The default value should be a number, not a string or variable name.
Fill both blanks to create a function with two default arguments and return their sum.
add <- function(a = [1], b = [2]) { a + b }
The function has two default numeric arguments: a defaults to 0 and b defaults to 2.
Fill all three blanks to define a function with default arguments and call it with one argument.
power <- function(base = [1], exponent = [2]) { base ^ exponent } result <- power([3]) result
The function defaults to base=2 and exponent=3. Calling power(5) sets base=5 and uses default exponent=3.