Yogesh Tiwari
2007-Aug-07 06:31 UTC
[R] how to convert decimal date to its equivalent date format(YYYY.mm.dd.hr.min.sec)
Hello R Users, How to convert decimal date to date as YYYY.mm.dd.hr.min.sec For example, I have decimal date in one column , and want to convert and write it in equivalent date(YYYY.mm.dd.hr.min.sec) in another next six columns. 1979.000000 1979.020833 1979.041667 1979.062500 Is it possible in R ? Kindly help, Regards, Yogesh -- Dr. Yogesh K. Tiwari, Scientist, Indian Institute of Tropical Meteorology, Homi Bhabha Road, Pashan, Pune-411008 INDIA Phone: 0091-99 2273 9513 (Cell) : 0091-20-258 93 600 (O) (Ext.250) Fax : 0091-20-258 93 825 [[alternative HTML version deleted]]
jim holtman
2007-Aug-08 00:27 UTC
[R] how to convert decimal date to its equivalent date format(YYYY.mm.dd.hr.min.sec)
Is this what you want?> x <- scan(textConnection("1979.000000+ + 1979.020833 + + 1979.041667 + + 1979.062500"), what=0) Read 4 items> # get the year and then determine the number of seconds in the year so you can > # use the decimal part of the year > x.year <- floor(x) > # fraction of the year > x.frac <- x - x.year > # number of seconds in each year > x.sec.yr <- unclass(ISOdate(x.year+1,1,1,0,0,0)) - unclass(ISOdate(x.year,1,1,0,0,0)) > # now get the actual time > x.actual <- ISOdate(x.year,1,1,0,0,0) + x.frac * x.sec.yr > > x.actual[1] "1979-01-01 00:00:00 GMT" "1979-01-08 14:29:49 GMT" "1979-01-16 05:00:10 GMT" [4] "1979-01-23 19:30:00 GMT">On 8/7/07, Yogesh Tiwari <yogesh.mpi at googlemail.com> wrote:> Hello R Users, > > How to convert decimal date to date as YYYY.mm.dd.hr.min.sec > > For example, I have decimal date in one column , and want to convert and > write it in equivalent date(YYYY.mm.dd.hr.min.sec) in another next six > columns. > > 1979.000000 > > 1979.020833 > > 1979.041667 > > 1979.062500 > > > > Is it possible in R ? > > Kindly help, > > Regards, > > Yogesh > > > > > > -- > Dr. Yogesh K. Tiwari, > Scientist, > Indian Institute of Tropical Meteorology, > Homi Bhabha Road, > Pashan, > Pune-411008 > INDIA > > Phone: 0091-99 2273 9513 (Cell) > : 0091-20-258 93 600 (O) (Ext.250) > Fax : 0091-20-258 93 825 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?