Reputation: 383
I am reading a Excel file with time as a column.
This column has values like
23:29:04
23:04:31
21:55:37
21:52:27
21:49:53
When I read this column using R , read column comes as a numeric value :
0.961469907
0.913622685
0.911423611
0.907094907
0.906250000
0.899490741
There is no correspondence between above mentioned Excel and R column values. These are just samples.
I tried using
strptime(TimeStamp,format="%H:%M:%S)
It gives all values as NA
.
Please suggest how to read time correctly in R.
Upvotes: 1
Views: 5564
Reputation: 740
Read the columns as string and wrap your strptime command with as.POSIXct:
as.POSIXct(strptime(TimeStamp,format="%H:%M:%S"))
Upvotes: -1
Reputation: 132706
These numbers are fractions of a day corresponding to times. Time objects are, e.g., implemented in package chron:
library(chron)
x <- c(0.961469907, 0.913622685, 0.911423611, 0.907094907, 0.906250000, 0.899490741)
x <- times(x)
print(x)
#[1] 23:04:31 21:55:37 21:52:27 21:46:13 21:45:00 21:35:16
Upvotes: 3