Printing Indexes From Replicate()

I am working with the R programming language.

I defined the following function:


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))

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


what would it mean to do it within the replicate() ? rather than anywhere else ... ? technically you can edit replicate or make your own version of replicate but then; is it still replicate ? I have to think that the short answer is no; but this shouldnt be a problem for you in your work given that you could get the information you want without that using other methods.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.