How do you define a function with a default argument in R?

How do you define a function with a default argument in R?

a) function_name <- function(x = 5)
b) function_name <- function(x <- 5)
c) function_name <- def(x = 5)
d) func function_name(x = 5)

Answer:

a) function_name <- function(x = 5)

Explanation:

In R, a default argument is set using the syntax function_name <- function(x = 5), where x takes the value 5 if not provided during the function call.

Reference:

R Programming – Functions MCQ Questions and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top