[R] Cumulates of snowfall within a given interval
Stefano Sofia
@te|@no@@o||@ @end|ng |rom reg|one@m@rche@|t
Fri Jul 30 11:26:46 CEST 2021
Thank you Petr,
simply perfect.
Thank you again
Stefano
(oo)
--oOO--( )--OOo--------------------------------------
Stefano Sofia PhD
Civil Protection - Marche Region - Italy
Meteo Section
Snow Section
Via del Colle Ameno 5
60126 Torrette di Ancona, Ancona (AN)
Uff: +39 071 806 7743
E-mail: stefano.sofia using regione.marche.it
---Oo---------oO----------------------------------------
________________________________________
Da: PIKAL Petr [petr.pikal using precheza.cz]
Inviato: venerdì 30 luglio 2021 10.37
A: Stefano Sofia; r-help mailing list
Oggetto: RE: Cumulates of snowfall within a given interval
Hi
I would use ?embed function.
nr <- which(rowSums(embed(mydf$hn, 2))>=80)
mydf[nr,]
But I feel strange that variant 40,50 should be accepted but 0, 90 should not. Both after two consecutive days result in more than 80cm cumulative snow. What about 1,80 how it differs from 0, 81. basically with your constrain zero means NA so if I change all zeroes to NA I get quite close.
> nr <- which(rowSums(embed(mydf$hn, 2))>=80)
> mydf[nr,]
data_POSIX hn
6 2018-02-06 40
13 2018-02-13 50
> nr <- which(rowSums(embed(mydf$hn, 4))>=100)
> mydf[nr,]
data_POSIX hn
12 2018-02-12 10
13 2018-02-13 50
> nr <- which(rowSums(embed(mydf$hn, 2))>=100)
> mydf[nr,]
data_POSIX hn
6 2018-02-06 40
>
Anyway, you need to polish the result a bit as in four consecutive days both 12 and 13 results in higher than 100 cm
Cheers
Petr
> -----Original Message-----
> From: R-help <r-help-bounces using r-project.org> On Behalf Of Stefano Sofia
> Sent: Friday, July 30, 2021 9:24 AM
> To: r-help mailing list <r-help using r-project.org>
> 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
> 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 days, three consecutive days or something like that)
> is higher than a threshold (it might be 80 cm, or 100 cm).
>
> I am trying with rle, but I really struggle to find an efficient algorithm.
> Could somebody help me with some hints?
>
> Thank you for your attention and your help
> Stefano
>
>
> init_day <- as.POSIXct("2018-02-01", format="%Y-%m-%d", tz="Etc/GMT-1")
> fin_day <- as.POSIXct("2018-02-20", format="%Y-%m-%d", tz="Etc/GMT-1")
> mydf <- data.frame(data_POSIX=seq(init_day, fin_day, by="1 day"))
> mydf$hn <- c(30, 0, 10, 50, NA, 40, 70, 0, 0, 0 , NA, 10, 50, 30, 30, 10, 0, 0, 90, 0)
>
> - if I choose a threshold of 100 cm in two days, I should get the 6th of
> February;
> - if I choose a threshold of 80 cm in two days I should get the 6th and the 13th
> of February, but not the 19th of February because this is a single day;
> - f I choose a threshold of 100 cm in four days, I should get the 12th of
> February.
>
> (oo)
> --oOO--( )--OOo--------------------------------------
> Stefano Sofia PhD
> Civil Protection - Marche Region - Italy
> Meteo Section
> Snow Section
> Via del Colle Ameno 5
> 60126 Torrette di Ancona, Ancona (AN)
> Uff: +39 071 806 7743
> E-mail: stefano.sofia using regione.marche.it
> ---Oo---------oO----------------------------------------
>
> ________________________________
>
> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere
> informazioni confidenziali, pertanto è destinato solo a persone autorizzate
> alla ricezione. I messaggi di posta elettronica per i client di Regione Marche
> possono contenere informazioni confidenziali e con privilegi legali. Se non si è
> il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo
> messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al
> mittente ed eliminarlo completamente dal sistema del proprio computer. Ai
> sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed
> urgenza, la risposta al presente messaggio di posta elettronica può essere
> visionata da persone estranee al destinatario.
> IMPORTANT NOTICE: This e-mail message is intended to be received only by
> persons entitled to receive the confidential information it may contain. E-mail
> messages to clients of Regione Marche may contain information that is
> confidential and legally privileged. Please do not read, copy, forward, or store
> this message unless you are an intended recipient of it. If you have received
> this message in error, please forward it to the sender and delete it
> completely from your computer system.
>
> --
> Questo messaggio stato analizzato da Libraesva ESG ed risultato non infetto.
> This message was scanned by Libraesva ESG and is believed to be clean.
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://urlsand.esvalabs.com/?u=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&e=5a635173&h=06ff70f3&f=y&p=y
> PLEASE do read the posting guide https://urlsand.esvalabs.com/?u=http%3A%2F%2Fwww.R-project.org%2Fposting-&e=5a635173&h=9e88a0d1&f=y&p=y
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
________________________________
AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.
--
Questo messaggio stato analizzato da Libraesva ESG ed risultato non infetto.
This message was scanned by Libraesva ESG and is believed to be clean.
More information about the R-help
mailing list