I have a file that formats time stamps like 25/03/2011 9:15:00 p.m.
How can I parse this text to a Date-Time class with either strptime or as.POSIXct?
Just came across this, as another option you can use stringr
package.
library(stringr)
data$date2 <- str_sub(data$date, end = -4)
# this removes the punctuation but holds onto the A/P values
data$date2 <- str_c(data$date2, 'm')
# adds the required m
It appears the AM/PM indicator can't include punctuation. Try it after removing the punctuation:
td <- "25/03/2011 9:15:00 p.m."
tdClean <- gsub("(.)\\.?[Mm]\\.?","\\1m",td)
as.POSIXct(tdClean, format="%d/%m/%Y %I:%M:%S %p", tz="UTC")
# [1] "2011-03-25 21:15:00 UTC"