[R] handle dates in R?

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Thu Sep 13 14:40:44 CEST 2007


Armstrong, Whit wrote:
> dts <- c("2004-8-1","2004-10-1","2001-9-1")
> strptime(dts,"%Y-%m-%d")
> julian(strptime(dts,"%Y-%m-%d")) 
>
>
>   
Why do people insist on missing the obvious?

> x <- c("2004-8-1","2004-10-1","2001-9-1")
> as.Date(x) - as.Date("1960-1-1")
Time differences in days
[1] 16284 16345 15219

>> -----Original Message-----
>> From: r-help-bounces at r-project.org 
>> [mailto:r-help-bounces at r-project.org] On Behalf Of zhijie zhang
>> Sent: Thursday, September 13, 2007 8:19 AM
>> To: R-help at stat.math.ethz.ch
>> Subject: [R] handle dates in R?
>>
>> Dear Rusers,
>>   I have some data in .csv file like "2004-8-1" and 
>> "2004-10-1", and i  need to convert them into days from the 
>> origin (January 1, 1960).
>> I have tried the function date.mmddyyyy(), but cannot get it. 
>> Anybody can show me how to handle the date data?
>>   Thanks very much!
>>
>> My dataset like:
>> time
>> 2004-8-1
>> 2004-10-1
>> 2001-9-1
>> 2002-9-1
>>
>>
>> --
>> With Kind Regards,
>>
>> oooO:::::::::
>> (..):::::::::
>> :\.(:::Oooo::
>> ::\_)::(..)::
>> :::::::)./:::
>> ::::::(_/::::
>> :::::::::::::
>> [*************************************************************
>> **********]
>> Zhi Jie,Zhang ,PHD
>> Tel:86-21-54237149
>> Dept. of Epidemiology,School of Public Health,Fudan 
>> University Address:No. 138 Yi Xue Yuan Road,Shanghai,China
>> Postcode:200032
>> Email:epistat at gmail.com
>> Website: www.statABC.com
>> [*************************************************************
>> **********]
>> oooO:::::::::
>> (..):::::::::
>> :\.(:::Oooo::
>> ::\_)::(..)::
>> :::::::)./:::
>> ::::::(_/::::
>> :::::::::::::
>>
>> 	[[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at 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.
>>
>>     
>
>
>
>
> This e-mail message is intended only for the named recipient(s) above. It may contain confidential information. If you are not the intended recipient you are hereby notified that any dissemination, distribution or copying of this e-mail and any attachment(s) is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by replying to this e-mail and delete the message and any attachment(s) from your system. Thank you.
>
>   
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help at 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.
>   


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list