Error Message while creating a customised Function

Hi,

I am a new learner of R. Creating a function to roll two virtual dice. The function should work like this: each time you call roll(), R should return the sum of rolling two dice. The code is as follows along with the error message:

roll<-function() {die<-1:6 dice<-sample(x=die,size=2,replace=TRUE) sum(dice)}
Error: unexpected symbol in "roll<-function() {die<-1:6 dice"

Appreciate guidance on the above issue.

Dont write dice on the same line as the die assignment bevause the parser doesnt understand what you are assigning to die. It seems like you want to assign more than only 1:6.
You can add ; to seperate the staments, but starting a new line would be the typical way to go.

1 Like

Thanks.
It helped and solved the problem.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.