Skip to content
Prev 371345 / 398506 Next

compounding precipitation based on whether falls within a day

Thanks for the reprex. Wouldn't have bothered without it.

The following is I believe **almost** what you want. It seems a bit clumsy
to me, so others may provide you something neater. But anyway...

## Convert POSIXct vector to dates
## There are 22 different days, not 21
date <- as.Date(prec_idx)

## Sum results by date at each i,j of the last 2 array dimensions
z <- lapply(unique(date),function(d)
   apply(prec[date==d,,],2:3,sum)
   )

## This gives a list with 22 3x4 matrices of sums.
## Convert to 3x4x22 array with

prec_daily <- array(unlist(z),dim=c(3,4,22))

## This is the **almost** part. You can use the aperm() function to reshape
the array if you like. I leave those pleasures to you.

HTH.

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Wed, Sep 13, 2017 at 9:52 AM, Morway, Eric <emorway at usgs.gov> wrote: