I have a data file which has three columns thus:
20010101 000000 0.833
20010101 000500 0.814
20010101 001000 0.794
20010101 001500 0.772
...
As is fairly clear to human eyes, the first two are date and time. I need to convert them into a POSIXct (or something else if it's better, but my limited past experience of dealing with timestamps in R is to use POSIXct). Normally, having pulled it in with read.table, I would use:
df$DateTime <- as.POSIXct(paste(df$Date, df$Time), format="%Y%m%d %H%M%S")
However, the second column seems to lose its leading zeroes (probably through a type coercion?), and thus it doesn't work correctly.
I've looked at Combine date as integer and time as factor to POSIXct in R and Converting two columns of date and time data to one, but both are using times with delimiters such as :, and so don't have the same problem.
How can I convert these columns to a POSIXct, please?
POSIXct
returns NA – Sinistrous