I import dates from Excel into R.
Some of the values appear as real numbers:
e.g. 43313.458055555559
I would like to convert these numbers into a
timestamp representation like this - 9/4/2018 11:45:35AM
Thanks in advance.
I import dates from Excel into R.
Some of the values appear as real numbers:
e.g. 43313.458055555559
I would like to convert these numbers into a
timestamp representation like this - 9/4/2018 11:45:35AM
Thanks in advance.
Based on G. Grothendieck's comment, try:
as.POSIXct(as.Date(43313.458055555559, origin = "1899-12-30"))
Just replace 43313.458055555559
by DataFrame.name$Column.name
.
Spreadsheets like Microsoft Excel on a Windows PC or OpenOffice.org represent datetimes as days and fraction of days since December 30, 1899 (usually). If
x
is a vector of such numbers thenas.Date("1899-12-30") + floor(x)
will give a vector of Date class dates with respect to Date’s origin. Similarlychron("12/30/1899") + x
will give chron dates relative to chron’s origin. Excel on a Mac usually represents dates as days and fraction of days since January 1, 1904 soas.Date("1904-01-01") + floor(x)
andchron("01/01/1904") + x
convert vectors of numbers representing such dates to Date and chron respectively. Its possible to set Excel to use either origin which is why the word usually was employed above.Source: https://www.r-project.org/doc/Rnews/Rnews_2004-1.pdf