0
0
R Programmingprogramming~10 mins

Function arguments in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a function that takes one argument and returns it.

R Programming
my_function <- function([1]) {
  return([1])
}
Drag options to blanks, or click blank then click option'
Ax
By
Cz
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the argument and return value.
Leaving the argument blank.
2fill in blank
medium

Complete the code to call the function with the argument 5.

R Programming
result <- my_function([1])
print(result)
Drag options to blanks, or click blank then click option'
A"5"
Bx
C5
Dmy_function
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of a number.
Passing the function name instead of an argument.
3fill in blank
hard

Fix the error in the function definition to correctly set a default argument value of 10.

R Programming
my_function <- function(x = [1]) {
  return(x)
}
Drag options to blanks, or click blank then click option'
A10
Bten
C"10"
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number for the default value.
Using a variable name that is not defined.
4fill in blank
hard

Fill both blanks to define a function with two arguments where the second has a default value.

R Programming
my_function <- function([1], [2] = 5) {
  return([1] + [2])
}
Drag options to blanks, or click blank then click option'
Ax
By
Cz
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same name for both arguments.
Not providing a default value for the second argument.
5fill in blank
hard

Fill all three blanks to create a function that multiplies two arguments and adds a third with a default value.

R Programming
my_function <- function([1], [2], [3] = 1) {
  return([1] * [2] + [3])
}
Drag options to blanks, or click blank then click option'
Aa
Bb
Cc
Dd
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same name for multiple arguments.
Not setting a default value for the third argument.