 # writing a function to simulate a pair of six sided dice

I have written my function down below:

dice.roll <- function(){
** dice <- sample(1:6, size = 2, replace = TRUE)**
** return(sum(dice))**
}

However, when I want to test it out on the following:

``````dice.roll(n = 1, seed = 0)
``````
``````dice.roll(n = 15, seed = 0)
``````
``````dice.roll(n = 2.4, seed = 2) # Q1(b)i.
dice.roll(n = 2, seed = 'a') # Q1(b)ii.
dice.roll(n = c(2, 4), seed = c(2, 1)) # Q1(b)iii.
dice.roll(n = 6, seed = 0.7) # Q1(b)iv.
``````

The function always returns an error: unused arguements

Any help is appreciated Hi Rachel, welcome!

The error message is giving you a clue, when you call the function you are passing two arguments (i.e. `n` and `seed`) but, you haven't defined this arguments in your function and also you are not using them in your code, so you have to check the code for your function again to make sure it does what is supposed to do.

For example, here I'm defining the `sample_function()` function which takes two arguments (`a` and `b`) and returns the sum of both numbers.

``````sample_function <- function(a, b) {
a + b
}

sample_function(a = 2, b = 5)
#>  7
``````

Created on 2019-09-30 by the reprex package (v0.3.0.9000)

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.