Thank you for all your suggestions.

Ivan's hint has been very easy to implement, a good solution indeed.


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.so...@regione.marche.it
---Oo---------oO----------------------------------------


________________________________
Da: Ivan Krylov <ikry...@disroot.org>
Inviato: sabato 31 agosto 2024 13:25
A: r-help@r-project.org; Stefano Sofia
Oggetto: Re: [R] aggregating data with quality control

[Non ricevi spesso messaggi di posta elettronica da ikry...@disroot.org. Per 
informazioni sull'importanza di questo fatto, visita 
https://aka.ms/LearnAboutSenderIdentification.]

� Sat, 31 Aug 2024 11:15:10 +0000
Stefano Sofia <stefano.so...@regione.marche.it> �����:

> Evaluating the daily mean indipendently from the status is very easy:
>
> aggregate(mydf$hs, by=list(format(mydf$data_POSIX, "%Y"),
> format(mydf$data_POSIX, "%m"), format(mydf$data_POSIX, "%d")),
> my.mean)
>
>
> Things become more complicated when I need to export also the status:
> this should be "C" when all 48 data have status equal to "C", and
> status "D" when at least one value has status ="D".
>
>
> I have no clue on how to do that in an efficient way.

You can make the status into an ordered factor:

# come up with some statuses
status <- sample(c('C', 'D'), 42, TRUE, c(.9, .1))

# convert them into factors, specifying that D is "more than" C
status <- ordered(status, c('C', 'D'))

Since the factor is ordered and can be subject to comparison like
status[1] < status[2], you can now use max() on your groups. If the
sample contains any 'D's, max() will return a 'D', because it's larger
than any 'C's. If the sample contains only 'C's, that's the maximal
value by default.

--
Best regards,
Ivan

________________________________

AVVISO IMPORTANTE: Questo messaggio di posta elettronica puo contenere 
informazioni confidenziali, pertanto e 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 
e il destinatario specificato, non leggere, copiare, inoltrare o archiviare 
questo messaggio. Se si e 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 necessita ed 
urgenza, la risposta al presente messaggio di posta elettronica puo 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.

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to