I want to calculate growing degree days with several bases, using minimum daily temp, and maximum daily temp. I would like to do this without a for loop if possible to minimize my code.
bases <- c(40,45,50)
tmin <- runif(10,30,70)
tmax <- runif(10,55,95)
I want to find the number of growing degree days for each base for each of the ten days I have fake temperature data for. There should be 10 output values for each of the 3 bases.
I've tried mapply as follows:
gdd_func <- function(tmin,tmax,bases){
(tmin + tmax)/2 - bases}
test <- mapply(gdd_func,tmin,tmax,bases)
This produces an incorrect output where I honestly don't know what it's doing. I want the output to be equal to running the above function 3 different times with the different bases. Each output would have 10 gdd values corresponding to the differing bases. How would I do this using an apply function of some kind? Or do I need something more?