Hi

> -----Original Message-----
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Stefano Sofia
> Sent: Tuesday, March 04, 2014 11:58 AM
> To: r-help@r-project.org
> Subject: [R] format for as.Date and inserting missing rows in a data
> frame
>
> Dear R users,
> I have a very long data frame (50 years, more than 1.5 million rows) of
> daily rainfall data from about 80 raingouges.
> The data frame that I have been given looks like
>
> Raingouge_number Station_number Year Month Day Rainfall
> 2004 2230 1951 1 1 2.60
> 2004 2230 1951 1 2 0.40
> 2004 2230 1951 1 3 0.00
> 2004 2230 1951 1 4 0.00
> 2004 2230 1951 1 5 0.20
> 2004 2230 1951 1 6 0.00
> 2004 2230 1951 1 7 0.00
> 2004 2230 1951 1 8 0.00
> 2004 2230 1951 1 9 0.00
> 2004 2230 1951 1 10 0.00
> ...
>
> There could be some missing days. I have two questions.
> 1st question:
> In order to handle eventual missing days I think that I have to
> transform three separate numbers (Year, Month and Day) to Date.
> Is there a format in as.Date suitable for this transformation or before
> all I have to set all the months and days to two digits, remove spaces
> and then apply as.Date with format "%Y%m%d"?

This shall do it if you put dataframe name instead of ...
as.Date(paste(...$Year, ...$Month, ...$Day, sep="."), format="%Y.%m.%d")

>
> 2nd question
> In case of missing day, the corresponding row will be missing and then
> I have to insert this new row and put -999.9 as Rainfall. Is there an
> easy way to do that?

Why? What is wrong with NA? What do you want to do with -999.9?
Anyway, you can get sequence of dates
?seq.Date

and merge it with your data.
?merge

I do not help you to put -999.9 instead of NA as I consider it extremely silly.

Regards
Petr

>
>
> Thank you for your help
> Stefano
>
>
> ________________________________
>
> 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]]


________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to