Re: [R] Cumulates of snowfall within a given interval

2021-08-01 Thread Richard O'Keefe
> x <- c(1,2,3) # a vector of numbers, such as snowfallsum > (cx <- cumsum(x)) # a vector of cumulative sums. 1 3 6 > i <- 1 # The starting point. > j <- 2 # The ending point. > cx[j] - cx[i-1] # sum of x[i] + ... + x[j] ERROR! > cx <- c(0, cx) # Oops, we need this step. > cx[j+1] - cx[i] So usin

Re: [R] Cumulates of snowfall within a given interval

2021-07-30 Thread Jim Lemon
Hi Stefano, Try using rollsum from the zoo package: library(zoo) rollsum_index<-function(x,window,val) return(which(rollsum(x,window) >= val)) rollsum_index(mydf$hn,2,80) [1] 6 13 18 19 Jim On Fri, Jul 30, 2021 at 5:24 PM Stefano Sofia wrote: > > Dear R users, > I have a data frame with daily

Re: [R] Cumulates of snowfall within a given interval

2021-07-30 Thread Stefano Sofia
iginal Message- > From: R-help On Behalf Of Stefano Sofia > Sent: Friday, July 30, 2021 9:24 AM > To: r-help mailing list > Subject: [R] Cumulates of snowfall within a given interval > > Dear R users, > I have a data frame with daily snow cumulates (these quantities are know

Re: [R] Cumulates of snowfall within a given interval

2021-07-30 Thread PIKAL Petr
essage- > From: R-help On Behalf Of Stefano Sofia > Sent: Friday, July 30, 2021 9:24 AM > To: r-help mailing list > Subject: [R] Cumulates of snowfall within a given interval > > Dear R users, > I have a data frame with daily snow cumulates (these quantities are known > a

[R] Cumulates of snowfall within a given interval

2021-07-30 Thread Stefano Sofia
Dear R users, I have a data frame with daily snow cumulates (these quantities are known as "hn" and are expressed in cm), from the 1st of December to the 30th of April, for more than twenty years. I would need to find days when the sum of a given short interval (I might choose two consecutive d