search for: prec_idx

Displaying 2 results from an estimated 2 matches for "prec_idx".

2017 Sep 13
2
compounding precipitation based on whether falls within a day
...In this case, the time index is hours since some predefined start time. I'd like to add up all the time indexes in 'prec' based on whether or not the corresponding hours fall within a given day. So, at the end of the small example below, there are two variables that I'm left with, prec_idx (an hourly sequence from beg_time to end_time) whose length is equal to the first index (the time index) of the 3D array of precipitation called prec. That is, I'd like to get a 3D array called prec*_daily* that has dimension prec*_daily*[21, 3, 4], where 21 is the number of days and the value...
2017 Sep 13
0
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 **a...