#' Growing and Freezing Degree Day Index
#'
#' Calculate GDD and FDD parameters values from a data.frame containing daily parameters of temperature
#'
#' @usage temp_gfdd(data,Dcol,Pcol,start,end,igt,sft)
#'
#' @param data An object of class "data.frame"containing daily temperature with a column with dates in format POSIXct.
#' @param Dcol an integer indicates the column number with dates
#' @param Pcol an integer indicates the column number with daily average temperatures
#' @param start a character string indicates date where calculation of GDD and FDD index started.
#' @param end a character string indicates date where calculation of GDD and FDD index finished.
#' @param igt value of Inferior Gdd Thresold.
#' @param sft value of Superior Fdd Thresold.
#'
#' @return A data.frame which contains date associate with daily average temperature, gdd and fdd index.
#' @references Choler, P. 2018. Winter soil temperature dependence of alpine plant distribution: Implications for anticipating vegetation changes under a warming climate. Perspectives in Plant Ecology, Evolution and Systematics 30: 6‑15.
#' @author Remy Moine <remymoine95@gmail.com>
#' @export
#'
temp_gfdd<-function(data,Dcol,Pcol,start,end,igt,sft){
if(missing(start)==T) start<-as.character(date[1])
if(missing(end)==T) end<-as.character(date[length(date)])
date<-as.character(data[,Dcol])
parameter<-data[,Pcol]
tmp<-data.frame(Date=date,
Temperature=parameter,
GDD=rep(-Inf,length(date)),
FDD=rep(-Inf,length(date)))
d1<-stringr::str_which(as.character(tmp$Date),start)
d2<-stringr::str_which(as.character(tmp$Date),end)
tmp$GDD[d1:d2]<-0
tmp$FDD[d1:d2]<-0
if (tmp$Temperature[d1]>=igt) tmp$GDD[d1]<-tmp$Temperature[d1] else tmp$GDD[d1]<-0
for (i in c((d1+1):d2)){
if (tmp$Temperature[i]>=igt){tmp$GDD[i]<-tmp$GDD[i-1]+tmp$Temperature[i]} else {
tmp$GDD[i]<-tmp$GDD[i-1]}}
if (tmp$Temperature[d1]<=sft) tmp$FDD[d1]<-tmp$Temperature[d1] else tmp$FDD[d1]<-0
for (i in c((d1+1):d2)){
if (tmp$Temperature[i]<=sft){tmp$FDD[i]<-tmp$FDD[i-1]+tmp$Temperature[i]} else {
tmp$FDD[i]<-tmp$FDD[i-1]}}
tmp$Date<-lubridate::as_date(tmp$Date)
sel<-which(tmp$GDD != -Inf)
tmp[sel,]
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.