How to convert dd/mm/yy to yyyy-mm-dd in R

Solution 1:

Use lubridate package

library(lubridate)
dmy("27/06/16")

Solution 2:

With base R

as.Date(as.character("27/06/16"), format = "%d/%m/%y")

Solution 3:

One option would be to convert both date formats into a common POSIX representation:

d1 <- strptime("27/06/16", "%d/%m/%y")
d2 <- strptime("2016-06-27", "%Y-%m-%d")

Since both d1 and d2 should be of the same R class, you can then just compare them as you wish.