# Number of times to repeat the process of tossing a fair coin 10 times
nsim <- 2
# Repeat for nsim times "tossing of a fair coin 10 times"
a <- replicate(nsim, rbinom(10, 1, 0.5))
a [,1] [,2]
[1,] 0 0
[2,] 1 0
[3,] 1 0
[4,] 1 0
[5,] 0 0
[6,] 1 1
[7,] 1 0
[8,] 1 0
[9,] 1 1
[10,] 0 0
# Calculate the relative frequency or sample proportion for every repetition
props <- colMeans(a)
props[1] 0.7 0.2