For a reproducible example, you need to give us some example data, at least
dput(head(leafbiom97)) dput(head(Litterfall_Ahmed97)) dput(head(GPP_Ahmed13)) Dan Daniel Nordlund, PhD Research and Data Analysis Division Services & Enterprise Support Administration Washington State Department of Social and Health Services > -----Original Message----- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ahmed > Attia > Sent: Thursday, June 22, 2017 9:50 AM > To: r-help > Subject: [R] For loop > > 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 > (Litterfall_Ahmed97). > > > 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 > > ______________________________________________ > 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. ______________________________________________ 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.