If I understand the text of the exercise correctly, the task is to iteratively draw a sample from the normal distribution, increasing the sample size at each step with the aim of empirically demonstrating that the larger the sample, the closer the variance and mean estimates to real values.
The following code should be useful.
set.seed(888)
#an empty object to be filled with the values obtained at each iteration
y<-NULL
for (k in 1:1000) {
#sample size for the iteration k
n <- 10+2*k
#sample drawing
sample <- rnorm(n, 0.3, 0.9)
#calculating mean and variance of the sample
var <- var(sample)
mean <- mean(sample)
#calculating the difference from the real values
d_var <- 0.81-var
d_mean <- 0.3-mean
#storing the values in a permanent dataframe
x <- data.frame(k, d_var, d_mean)
y <- rbind(y,x)
}
plot(y$k, y$d_var)
plot(y$k, y$d_mean)