Skip to content
Prev 349962 / 398513 Next

Sum of some months totals

If you want to calculate the number of days having greater than a certain
threshold of rain within a range of months, a function like this might
serve your needs.

raindays <- function(data, monStart=1, monEnd=3, threshold=0.85) {
  with(data, {
    selRows <- Month >= monStart & Month <= monEnd & Rain > threshold
    days <- tapply(selRows, Year, sum)
    return(days)
  })
}

raindays(kitale)

Jean

On Tue, Apr 14, 2015 at 2:46 AM, Frederic Ntirenganya <ntfredo at gmail.com>
wrote: