2

I have a data set that I believe is given in 20 minute increments. The year and month columns are given in a standard decimal value. But the the Day and Hour/Min/Sec data are given as a combined decimal (First digit is "Day", following decimal places are time). As example:

Year      month decimal.day
2014       1      1.0139
2014       1      1.0278
2014       1      1.0417
2014       1      1.0556
2014       1      1.0694
2014       1      1.0833
2014       1      1.0972
2014       1      1.1111
2014       1      1.1250
2014       1      1.1389
2014       1      1.1528
2014       1      1.1667
2014       1      1.1806
2014       1      1.1944
  .        .      .
  .        .      .
  .        .      .
  .
 2014      1      1.9722
 2014      1      1.9861
 2014      1      2.0000
 2014      1      2.0139
 2014      1      2.0278
 2014      1      2.0417
 2014      1      2.0556
 2014      1      2.0694
 2014      1      2.0833

Using R, is it possible to convert the decimal.day column into a standard time format? In the end I would like to concatenate all 3 columns into a standard POSIX "YYYY-MM-DD HH:MM:SS" format.

Vinterwoo
  • 3,843
  • 6
  • 36
  • 55
  • 3
    possible duplicate of [How convert decimal to POSIX time](http://stackoverflow.com/questions/14483629/how-convert-decimal-to-posix-time) – jeremycg Aug 26 '15 at 20:27
  • The suggested duplicate question deals with only a time component in the decimal number (H:M:S). The above decimal numbers incorporate a date and time element (Day H:M:S) – Vinterwoo Aug 26 '15 at 21:11

1 Answers1

3

You can use as.POSIXct() to do so:

as.POSIXct.numeric((df$decimal.day-1)*24*3600, 
                   origin=paste(df$Year, df$month, 1, sep = "/"), tz="GMT")

Note the -1 to balance starting the first day of the month

HubertL
  • 19,246
  • 3
  • 32
  • 51