[R] Create a vector without using an external 'if statement'

Stefano Sofia stefano.sofia at regione.marche.it
Tue Apr 2 14:40:41 CEST 2013


Dear R-users,
suppose I have three dataframes like these

df1:
mydate min_temp
31032013  12
01042013 8
02042013 -999

df2:
mydate min_temp
31032013  10
01042013 11
02042013 14

df3:
mydate min_temp
31032013  4
01042013 3
02042013 5

where -999 means that the temperature data is not available (at the moment I cannot change it to NA because I am not the db administrator);
suppose also that oggi is 02042013.

I need to create an array of all min_temp, having NA where min_temp is -999.

my_array <- c(df1$min_temp[df1$mydate==oggi], df2$min_temp[df2$mydate==oggi], df3$min_temp[df3$mydate==oggi])

creates
(-999,14,5)
while I need
(NA,14,5)

Can I do it directly while I create my_array, without using an external if statement?

Thank you for your help
Stefano Sofia

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.


More information about the R-help mailing list