Sample size, P-values (its relationship), and data visualization with plots. ggplot and T test
In this code you do not need the loop:

sample &lt;- 1:nsim
t_result &lt;- (mean(ctrl_mean)-mean(treated_mean)) /
  sqrt((ctrl_sd^2/(sample))+(treated_sd^2/(sample)))
# OR:
t_result &lt;- (mean(ctrl_mean) - mean(treated_mean)) /
  sqrt((ctrl_sd^2 + treated_sd^2) / sample)


why the set seed?