Search code examples
rsampledice

How could i display the dice sample space by R?


I am a R beginner.If i want to show that throwing the two dice's all sample space like (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (2,1) (2,2) ... (2,6) (3,1) ... (6,6)

My thought is x<-1:6 y<-1:6, but i want to know how to generate (x,y). The question perplexed me a period of time.


Solution

  • You can use expand.grid:

    > expand.grid(x=1:6, y=1:6)
       x y
    1  1 1
    2  2 1
    3  3 1
    4  4 1
    5  5 1
    6  6 1
    7  1 2
    8  2 2
    9  3 2
    10 4 2
    11 5 2
    12 6 2
    13 1 3
    ...