I am pretty new to R and have a couple of questions about a loop I am attemping to execute. I will try explain myself as best as possible reguarding what I wish the loop to do.
for(i in (1988:1999,2000:2006)){
yearerrors=NULL
binding=do.call("rbind.fill",x[grep(names(x), pattern ="1988.* 4._ data=")])
cmeans=lapply(binding[,2:ncol(binding)],mean)
datcmeans=as.data.frame(cmeans)
finvec=datcmeans[1,]
kk=0
result=RMSE2(yields[(kk+1):(kk+ncol(binding))],finvec)
kk=kk+ncol(binding)
yearerrors=c(result)
}
yearerrors
First I wish for the loop to iterate over file names of data. Specifically over the years 1988-2006 in the place where 1988 is placed right now in the binding statement. x is a list of data files inputted into R and the 1988 is part of the file name. So, I have file names starting with 1988,1989,...,2006.
yields is a numeric vector and I would like to input the indices of the vector into the function RMSE2 as indicated in the loop. For example, over the first iteration I wish for the indices 1 to the number of columns in binding to be used. Then for the next iteration I want the first index to be 1 more than what the previous iteration ended with and continue to a number equal to the number of columns in the next binding statement. I just don't know if what I have written will accomplish this.
Finally, I wish to store each of these results in the vector yearerrors and then access this vector afterwards.
Thanks so much in advance!