Complete the code to define a function named greet that prints a message.
greet <- function() {
print([1])
}The print function needs a string inside quotes to display the message.
Complete the code to call the greet function.
[1]()To run the function, use its name followed by parentheses.
Fix the error in the function definition to accept a name parameter.
greet <- function([1]) { print(paste("Hello," , name)) }
The function needs a parameter named 'name' to use it inside.
Fill both blanks to create a function that adds two numbers and returns the result.
add_numbers <- function(a, b) {
result <- a [1] b
return([2])
}The function adds a and b, then returns the result variable.
Fill all three blanks to create a function that checks if a number is positive, negative, or zero.
check_number <- function(num) {
if (num [1] 0) {
return("Positive")
} else if (num [2] 0) {
return("Negative")
} else {
return([3])
}
}The function uses > and < to check positive or negative, and returns "Zero" if neither.
