[R] For loop

Ahmed Attia ahmedatia80 at gmail.com
Thu Jun 22 18:50:29 CEST 2017

Hello R users,

The code below is for loop in R that I want to do to following
calculation at each time i and i-1 in 2:75 dataset

ac = ((LeafBiog at date i
-LeafBiog at date i-1, dataset = leafbiom97) + (littperiod at date i,
dataset= Litterfall_Ahmed97))/(sum (GPP from date i-1 to date i,
dataset=GPP_Ahmed13)/2) .

#code for loop

GPP_Ahmed13$Date <- as.Date(GPP_Ahmed13$Date, '%Y/%m/%d')
Litterfall_Ahmed97$Date <- as.Date(Litterfall_Ahmed97$Date, '%Y/%m/%d')
leafbiom97$Date <- as.Date( leafbiom97$Date, '%Y/%m/%d')
for (i in 2:75){
  (leafbiom97$LeafBiog[leafbiom97$Date == "i"] -
     leafbiom97$LeafBiog[leafbiom97$Date == "i-1"]+
     Litterfall_Ahmed97$littperiod[Litterfall_Ahmed97$Date =="i"])/
    (sum(GPP_Ahmed13$GPP[GPP_Ahmed13$Date >= "i-1" &
                           GPP_Ahmed13$Date <= "i"])/2)

#Error in charToDate(x) :

Thanks for your help

Ahmed Attia, Ph.D.
Agronomist & Soil Scientist

More information about the R-help mailing list