There are a bunch of things wrong here, although without a reproducible example I can't really fix most of them.
- You're overwriting SH within the loop. - You're running the regression 2641 times, even though the result never changes. - You're never predicting from your linear model using the other data not in the regression. - Leaf biomass data is never used for anything. I would have thought that you would use leaf biomass as the predictor variable, not Date. - I'm not sure why you want the cumulative sum of stand height; that doesn't make sense to me. I'm guessing you want: height.model <- lm(height ~ leafbiomass, data = Stand_Height) pred.height <- predict(height.model, leafbiom) # not sure about the reasoning behind this SH <- cumsum(pred.height) You don't need a loop. Overwriting SH is the biggest R problem; the rest of my questions have to do with what your objective actually is, like what you are modeling and what you are doing with the predictions. But my sample code might be enough to get you headed in the right direction regardless. Sarah On Fri, Jun 30, 2017 at 9:27 AM, Ahmed Attia <ahmedati...@gmail.com> wrote: > Hi folks, > > I have 25 stand height observations over 7 years period and daily > leafbiomass data during this period. I want to use the 25 plant height > observations as inputs and predict the daily stand height during the 7 > years. > > > SH=matrix(data=NA , nrow = 2641, ncol = 1) > for (i in 1:2641) { > SH<- predict(lm(height~Date, data=Stand_Height)); > > dl=leafbiom$Date[i-1]; > de=leafbiom$Date[i]; > SH[i]=sum(SH[leafbiom$Date==de&leafbiom$Date==dl]) > > > } > SH > > > The SH output is the prediction of Stand height in 25 observations > only and provides NA for the remaining 2616 iterations. > > Thanks for your help. > > > > Ahmed Attia, Ph.D. > Agronomist & Soil Scientist > -- Sarah Goslee http://www.functionaldiversity.org ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.