I am trying to avoid a loop in R. But I am having difficulties. At the moment this is the code that I have but I would really like to know if there is a direct way to do it (no loop). Triangle is just a IxJ matrix
I = 10
J = 10
xi <- rep(0,J)
xi[1] <- 1
for(j in 2:J){
xi[j]<-(1/(I-j+1))*sum(log(Triangle[1:(I-j+1),j]/Triangle[1:(I-j+1),j-1]))
}
1:(j+stuff)and you can't vectorize that.vectorizefunction. You'd have to run a time trial to see if it saves you anything in this simple case.