[R] add only the 1st of May with POSIXct

Stefano Sofia @te|@no@@o||@ @end|ng |rom reg|one@m@rche@|t
Tue May 28 17:23:21 CEST 2024


Dear R-list users,

>From an initial and a final date I create a sequence of days using POSIXct.

If this interval covers all or only in part the months from May to October, I need to get rid of the days from the 2nd of May to the 31st of October:


a <- as.POSIXct("2002-11-01", format = "%Y-%m-%d", tz="Etc/GMT-1")

b <- as.POSIXct("2004-06-01", format = "%Y-%m-%d", tz="Etc/GMT-1")

mydf <- data.frame(data_POSIX=seq(as.POSIXct(paste(format(a, "%Y-%m-%d"), "09:00:00", sep=""), format="%Y-%m-%d %H:%M:%S", tz="Etc/GMT-1"), as.POSIXct(paste(format(b, "%Y-%m-%d"), "09:00:00", sep=""), format="%Y-%m-%d %H:%M:%S", tz="Etc/GMT-1"), by="1 day"))


If I execute

as.data.frame(mydf[format(mydf$data_POSIX,"%m") %in% c("11", "12", "01", "02", "03", "04"), ])

the interval will be

from 2002-11-01 09:00:00 to 2003-04-30 09:00:00

and from 2003-11-01 09:00:00 to 2004-04-30 09:00:00


but I need also 2003-05-01 09:00:00 and 2004-05-01 09:00:00


How can I solve this problem?


Thank you for your attention and your help

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----------------------------------------

________________________________

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.

	[[alternative HTML version deleted]]



More information about the R-help mailing list