I am working with the R programming language.
I defined the following function:
set.seed(123)
fn <- function(){
a_j = rnorm(100,10,1)
b_j = rnorm(100,10,1)
c_j = rnorm(100,10,1)
sum_j = a_j + b_j + c_j
d_i = mean(rnorm(10, sum_j, sum_j))
print(d_i)
return(d_i)
}
I then used the replicate()
function in R to repeat my function n = 100 times:
results <- replicate(100, fn())
[1] 23.8183
[1] 23.27264
[1] 42.64727
My Question: When the replicate()
function is running - is it possible to add a "print" statement within the replicate()
function itself that prints the "replicate" index number?
Something like:
[1] 23.8183 , 1
[1] 23.27264, 2
[1] 42.64727, 3
Thanks!