This is the R code only copy paste
#setting a parameters of Bi(n, p)
n <- 1000
p <- 0.4
#dataframe
df <- data.frame(bi = rbinom(n, 1, p)  ,count = 0, mean = 0)
ifelse(df$bi[1] == 1, df[1, 2:3] <- 1, 0)
for (i in 2 : n){
  df$count <- ifelse(df$bi == 1, df$count<-df$count[i - 1]+1, df$count[i - 1])
  df$mean <- df$count / i
}
#graph
plot(df$mean, type='l',
      main = "Simulation of the Law of Large Numbers",
      xlab="Numbers", ylab="Sample mean")
abline(h = p, col="blue")
