Part of the data looks like:
head(my_data[,c(1,2)], 3)
Date Time
1 16/12/2006 17:24:00
2 16/12/2006 17:25:00
3 16/12/2006 17:26:00
By the way, str() $Date, $Time
are all chr now.
I want to keep them in two cols with correct format, so I use
x <- as.Date(my_data$Date, "%d/%m/%Y")
to get the 1st col in date format :
x[1:5]
[1] "2006-12-16" "2006-12-16" "2006-12-16" "2006-12-16" "2006-12-16"
But in the 2nd col, when I'm trying to use
y <- strptime(my_data$Time, "%H:%M:%S")
The output automatically add default date and timezone of my computer.
y[1:4]
[1] "2017-01-10 17:24:00 CST" "2017-01-10 17:25:00 CST"
[2] "2017-01-10 17:26:00 CST" "2017-01-10 17:27:00 CST"
What should I do if I just want to keep the time, without date and timezone?
Is sub()
with some regular expression the only way to achieve this?