0

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.

Kevin
  • 59
  • 6
  • 1
    What is your expected output? Do you want to display `(1,1)(1,2)` on the screen? Or having the results stored in an object (list, matrix,...)? –  Sep 01 '15 at 00:52
  • I want to show throwing the two dice's all sample space like (x=1,y=1)...(x=6,y=6) – Kevin Sep 01 '15 at 00:57
  • 6
    `expand.grid(x=1:6, y=1:6)` – jeremycg Sep 01 '15 at 00:59

2 Answers2

2

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
... 
zero323
  • 322,348
  • 103
  • 959
  • 935
0

You can use library prob from CRAN Your answer should be something like:

library(prob)
rolldie(2)

Regards

user1997567
  • 439
  • 4
  • 19