Please look at the following code in R
i=1
a1=function(x){
print(i)
i=i+1
return(x^2)}
a2=replicate(5,a1(2))
I wish to have an output as 1 2 3 4 5
Can anyone help me with this? However I don't want to write for-loops. I wish to keep the replicate function as it is. Thanks for suggestions/help.