> outspc = c("Heads","Tails") #Outcome space
> z = sample(outspc, 20, replace=TRUE)#Flip 20 times
> z # 1ST TIME
[1] "Tails" "Tails" "Heads" "Heads" "Heads"
[6] "Heads" "Heads" "Tails" "Tails" "Heads"
[11] "Heads" "Heads" "Heads" "Tails" "Tails"
[16] "Heads" "Heads" "Tails" "Heads" "Heads"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #2ND TIMES
[1] "Tails" "Tails" "Heads" "Tails" "Heads"
[6] "Heads" "Tails" "Tails" "Tails" "Tails"
[11] "Tails" "Tails" "Tails" "Tails" "Tails"
[16] "Heads" "Tails" "Heads" "Heads" "Heads"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z # 3RD TIMES
[1] "Tails" "Heads" "Heads" "Tails" "Heads"
[6] "Heads" "Heads" "Heads" "Heads" "Tails"
[11] "Heads" "Heads" "Heads" "Heads" "Tails"
[16] "Tails" "Heads" "Heads" "Heads" "Tails"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z 4TH TIMES
[1] "Tails" "Heads" "Tails" "Heads" "Heads"
[6] "Heads" "Heads" "Heads" "Tails" "Tails"
[11] "Tails" "Tails" "Tails" "Tails" "Heads"
[16] "Heads" "Tails" "Tails" "Heads" "Tails"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #5TH TIMES
[1] "Tails" "Heads" "Tails" "Tails" "Heads"
[6] "Heads" "Tails" "Heads" "Tails" "Heads"
[11] "Tails" "Heads" "Tails" "Heads" "Tails"
[16] "Tails" "Tails" "Heads" "Tails" "Tails"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #6TH TIMES
[1] "Heads" "Heads" "Heads" "Tails" "Heads"
[6] "Heads" "Heads" "Heads" "Heads" "Tails"
[11] "Heads" "Heads" "Tails" "Heads" "Heads"
[16] "Heads" "Tails" "Heads" "Heads" "Tails"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #7TH TIMES
[1] "Heads" "Heads" "Tails" "Heads" "Tails"
[6] "Tails" "Heads" "Heads" "Heads" "Heads"
[11] "Tails" "Tails" "Heads" "Tails" "Heads"
[16] "Heads" "Heads" "Heads" "Tails" "Heads"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #8TH TIMES
[1] "Heads" "Tails" "Heads" "Heads" "Heads"
[6] "Tails" "Heads" "Heads" "Tails" "Tails"
[11] "Heads" "Heads" "Heads" "Heads" "Heads"
[16] "Tails" "Heads" "Heads" "Heads" "Heads"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #9TH TIMES
[1] "Heads" "Tails" "Tails" "Heads" "Heads"
[6] "Heads" "Tails" "Tails" "Tails" "Heads"
[11] "Tails" "Heads" "Heads" "Heads" "Heads"
[16] "Heads" "Heads" "Heads" "Tails" "Heads"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #10TH TIMES
[1] "Heads" "Tails" "Tails" "Tails" "Heads"
[6] "Tails" "Heads" "Tails" "Heads" "Heads"
[11] "Tails" "Heads" "Heads" "Heads" "Heads"
[16] "Tails" "Heads" "Tails" "Heads" "Heads"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #11TH TIMES
[1] "Tails" "Heads" "Heads" "Tails" "Heads"
[6] "Tails" "Tails" "Tails" "Heads" "Tails"
[11] "Heads" "Heads" "Heads" "Tails" "Heads"
[16] "Heads" "Heads" "Heads" "Heads" "Tails"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #12TH TIMES
[1] "Heads" "Heads" "Tails" "Heads" "Heads"
[6] "Tails" "Heads" "Tails" "Tails" "Heads"
[11] "Tails" "Heads" "Heads" "Heads" "Tails"
[16] "Tails" "Tails" "Heads" "Heads" "Heads"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #13TH TIMES
[1] "Heads" "Tails" "Tails" "Heads" "Tails"
[6] "Heads" "Tails" "Heads" "Heads" "Heads"
[11] "Heads" "Heads" "Tails" "Tails" "Heads"
[16] "Heads" "Tails" "Heads" "Heads" "Heads"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #14TH TIMES
[1] "Heads" "Tails" "Tails" "Tails" "Tails"
[6] "Tails" "Tails" "Heads" "Heads" "Heads"
[11] "Tails" "Heads" "Heads" "Tails" "Tails"
[16] "Tails" "Tails" "Heads" "Heads" "Tails"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #15TH TIMES
[1] "Tails" "Heads" "Heads" "Heads" "Heads"
[6] "Tails" "Heads" "Heads" "Heads" "Heads"
[11] "Tails" "Heads" "Heads" "Heads" "Tails"
[16] "Heads" "Heads" "Tails" "Tails" "Heads"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #16TH TIMES
[1] "Heads" "Tails" "Tails" "Tails" "Tails"
[6] "Tails" "Tails" "Tails" "Heads" "Heads"
[11] "Tails" "Heads" "Heads" "Tails" "Tails"
[16] "Heads" "Tails" "Heads" "Tails" "Tails"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #17TH TIMES
[1] "Tails" "Heads" "Tails" "Heads" "Tails"
[6] "Tails" "Tails" "Tails" "Heads" "Heads"
[11] "Heads" "Heads" "Tails" "Heads" "Heads"
[16] "Heads" "Heads" "Heads" "Tails" "Heads"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #18TH TIMES
[1] "Heads" "Heads" "Tails" "Tails" "Tails"
[6] "Heads" "Tails" "Heads" "Heads" "Heads"
[11] "Heads" "Tails" "Heads" "Tails" "Heads"
[16] "Heads" "Tails" "Tails" "Heads" "Tails"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #19TH TIMES
[1] "Tails" "Tails" "Heads" "Tails" "Heads"
[6] "Tails" "Tails" "Heads" "Heads" "Heads"
[11] "Heads" "Heads" "Heads" "Tails" "Heads"
[16] "Heads" "Tails" "Heads" "Tails" "Heads"
> outspc = c("Heads","Tails")
> z = sample(outspc, 20, replace=TRUE)
> z #20TH TIMES
[1] "Heads" "Heads" "Tails" "Heads" "Heads"
[6] "Tails" "Tails" "Heads" "Tails" "Tails"
[11] "Heads" "Tails" "Heads" "Tails" "Tails"
[16] "Tails" "Tails" "Heads" "Tails" "Tails" But flipping the coin by hand is very time consuming so using Rcode > n = 5000
> outc = sample(c("Head","Tail"), n, replace=T)
> z = cumsum(outc=="Head")/seq(1,n)
> plot(z, xlab="Flips", ylab="Frequency of Heads",type="l")
> abline(h=0.5, col="grey")
If We want to roll six sided die 15 times1 St time > outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 6 2 6 6 1 2 6 6 2 6 5 3 1 4 2
2nd times > outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 3 2 4 4 4 1 2 6 1 5 3 5 2 1 4 3rd times
> outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 2 3 5 4 6 4 6 1 1 5 3 3 2 6 4
4th times
> outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 1 3 6 3 4 4 2 6 6 3 3 2 1 5 2
5th times
> outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 6 6 4 3 4 5 4 3 3 4 1 2 2 4 6
6th times
> outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 3 5 1 1 3 4 3 3 1 6 5 2 1 2 4
7th times
> outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 5 6 3 3 5 4 5 5 3 1 2 1 2 5 5
8th times
> outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 2 2 6 4 3 3 6 6 2 4 3 5 1 4 4
9th times
> outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 3 5 5 6 6 1 3 6 3 5 1 3 4 1 5 10th times
> outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 4 5 6 5 2 5 1 4 1 3 4 3 6 5 5
11th times
> outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 5 6 3 4 1 1 6 3 5 3 3 5 3 3 4
12th times outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 6 5 4 1 1 2 2 5 1 5 2 4 1 4 4 13th times
> outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 6 3 2 4 1 5 4 5 2 3 1 6 5 1 5 14th times
> outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 6 6 6 1 2 1 6 6 3 2 1 2 4 6 1 15th times
> outspc=seq(1,6)
> y = sample(outspc, 15, replace=TRUE)
> y
[1] 6 4 3 5 4 4 4 4 2 3 3 5 3 4 1

0 Comments