'Comparing emperical var and means to theortical in R

I have and array "exp_v" with random numbers from exponential distribution and I want to compare the emperical mean and var to the theoretical ones.

My problem with my code is that I get only one value instead of getting 1000 different values.

This is my R code so far:

set.seed(3)
N = 1000
X = c()
u = runif(1000,0,1)

hist(u)

lambda = 1
formula = (-1/lambda)*log(1-u)

for (i in 0:N){
  exp_v = c(formula)
}

hist(exp_v)

realMean = lambda**-1
realVar = lambda**-2

mean_sim = c()
var_sim = c()
error_mean = c()
error_var = c()
for (i in 0:N){
  
  mean_sim = mean(exp_v)
  var_sim = var(exp_v)
  error_mean = abs(mean_sim - realMean)
  error_var = abs(var_sim - realVar)
  
  }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source