I have a simple function in the R language, for instance:
f<-function(x){
y=(x+2)/3
return(y)
}
I want to evaluate this function five times on its own outputs, i.e., y1=f(x), y2=f(f(x)), y3=f(f(f(x))), y4=f(f(f(f(x)))), y5=f(f(f(f(f(x))))).
Is there a simpler way to do it in the form of one function, for instance the function with two arguments when the first argument is x and the second argument is the number of evaluation times, i.e., n. For instance, for x=3 and n=5 I would like to have the function f2<-(x=3,n=5) whose output would be in the form of a vector or a list of the length equal to n with the values:
y1=f(3)=1.666667
y2=f(f(3))=1.222222
y3=f(f(f(3)))=1.074074
y4=f(f(f(f(3))))=1.024691
y5=f(f(f(f(f(3)))))=1.00823
How to write such one function in the R ?