set.seed(1)
sample1= rnorm(n= 10, mean= 20, sd= 2)
sample1
##  [1] 18.74709 20.36729 18.32874 23.19056 20.65902 18.35906 20.97486 21.47665
##  [9] 21.15156 19.38922
#Generate first example for 10 random values with a mean of 20 and a standard deviation of 2.
round (mean (sample1), 3)
## [1] 20.264
#calculate mean of the sample 1
#SECOND SAMPLE
set.seed(2)
sample2= rnorm(n= 10, mean= 20, sd= 2)
sample2
##  [1] 18.20617 20.36970 23.17569 17.73925 19.83950 20.26484 21.41591 19.52060
##  [9] 23.96895 19.72243
#Generate second sample for 10 random variables
round (mean (sample2), 3)
## [1] 20.422
#Mean of sample 2. It is different each time a new sample is generated
sample_means= vector(mode= "numeric")

for(i in 1:100){
  set.seed(i)
  sample_means= c(sample_means, round (mean(rnorm(n= 10, mean= 20, sd= 2)), 2))
}
#Generate 100 samples each with 10 values, for each sample let’s compute the sample mean, and let’s compare all 100 samples means to the population mean of 20.
plot (sample_means, xlab= "Sample", ylab= "Xbar", yaxt = "n")
axis(2, at=seq(18,22,0.5), labels=seq(18,22,0.5))
abline(h= 20)

#plot results obtained 
sample_means2= vector(mode= "numeric")

for(i in 1:100){
  set.seed(i)
  sample_means2= c(sample_means2, round (mean(rnorm(n= 50, mean= 20, sd= 2)), 2))
}
#Here, increasing the value of n the sample will be more accurate.
plot (sample_means2, xlab= "Sample", ylab= "Xbar", yaxt = "n")
axis(2, at=seq(18,22,0.5), labels=seq(18,22,0.5))
abline(h= 20)

#as could be seen in the graph, points are closer to the line.