Reputation: 3542
I want to parse date format like "Apr-13", "May-14", which I want to parse it to POSIX time "2013-04-01 UTC", "2014-05-01 UTC". I tried using lubridate
package in R:
parse_date_time("Apr-13", "my")
parse_date_time("Apr-13", "by")
parse_date_time("Apr-13", "%b-%y")
parse_date_time("Apr-13", "%m-%y")
fast_strptime("Apr-13", "%b-%y")
But all of them failed to parse, is it possible to parse this using lubridate
? Any other package is also welcome.
Upvotes: 1
Views: 1278
Reputation: 56249
Try this example:
library(lubridate)
x <- c("Apr-13", "May-14")
#add DD as 01
x <- paste("01",x,sep="-")
#result
dmy(x)
#output
#[1] "2013-04-01 UTC" "2014-05-01 UTC"
Upvotes: 4