[R] Reading a datetime vector

Jim Lemon drjimlemon at gmail.com
Wed Feb 24 04:19:38 CET 2016


Hi Doug,
I see what the problem is now. When your Excel file is read in with
read.xlsx2, the DateTimeStamp is read as days since Microsoft's time epoch
(see earlier posts on this). As these values are numeric, they cannot be
converted in the same way as a human readable date/time string. The easiest
way I could think of to get around this is to export the XLSX file as CSV.
Then you will have the date/time strings and can convert them to POSIX
date/time values. Note that your format spec was slightly wrong - day is
first.

# first export the EXCEL file as a CSV file then
df2_TZ = read.csv("/media/KINGSTON/DF_exp2.csv",stringsAsFactors=FALSE)
df2_TZ$DateTimeStamp<-strptime(df2_TZ$DateTimeStamp,"%d/%m/%Y %H:%M")
# and I get
df2_TZ$DateTimeStamp
 [1] "2013-01-01 00:00:00 EST" "2013-01-01 01:00:00 EST"
 [3] "2013-01-02 23:15:00 EST" "2013-01-02 23:30:00 EST"
 [5] "2013-01-02 23:45:00 EST" "2013-01-03 00:00:00 EST"
 [7] "2013-01-03 01:00:00 EST" "2013-01-03 01:15:00 EST"
 [9] "2013-01-04 23:00:00 EST" "2014-11-24 15:04:00 EST"
[11] "2013-01-04 23:15:00 EST" "2013-01-04 23:30:00 EST"
[13] "2013-01-05 00:30:00 EST" "2013-01-05 00:45:00 EST"
[15] "2013-01-26 00:00:00 EST" "2013-07-19 15:42:00 EST"

Jim

	[[alternative HTML version deleted]]



More information about the R-help mailing list