When i strip date and time using strptime()
it converts my time from class POSIXct
to character
.
> head(data)
timestamps value
1 2017-10-01 00:00:00 8.424
2 2017-10-01 01:00:00 7.832
3 2017-10-01 02:00:00 6.320
4 2017-10-01 03:00:00 6.696
5 2017-10-01 04:00:00 5.448
6 2017-10-01 05:00:00 4.992
> data$time <- format(data$timestamps,"%H:%M:%S")
> str(data)
'data.frame': 226 obs. of 3 variables:
$ timestamps: POSIXct, format: "2017-10-01 00:00:00" "2017-10-01 01:00:00" "2017-10-01 02:00:00" ...
$ value : num 8.42 7.83 6.32 6.7 5.45 ...
$ time : chr "00:00:00" "01:00:00" "02:00:00" "03:00:00" ...
You can see it converts time to character
. How do i strip time with same class POSIXct
?
This link here gives how to convert it to Integer and take hours, minutes values alone. I want my timestamp to convert it to Posixct and Not Integer. Also read the line given in that link.I would not advise to do that if you want to do any further operations on your data. However, it might be convenient to do that if you want to plot the results.
And this doesn't work either : as.integer(format(Sys.time(), "%H%M%S"))