[R] Reading a datetime vector
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Wed Feb 24 05:13:10 CET 2016
You are overthinking this. The answer is in the help file for read.xls2.
--
Sent from my phone. Please excuse my brevity.
On February 23, 2016 7:19:38 PM PST, Jim Lemon <drjimlemon at gmail.com> wrote:
>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]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.
[[alternative HTML version deleted]]
More information about the R-help
mailing list