I have a vector of dates stored as strings, some of these are in YYYY-mm-dd format and some are in YYYY-dd-mm format. I need to work out how to convert these as dates. Fortunately, all instances in the YYYY-dd-mm format are after the 12 day of any month so they are easily discernible.

Have tried

```
dates <- c("2017-12-31","2017-12-30","2017-29-12","2017-28-12")
dates <- as.Date(dates, format = c("%Y-%m-%d","%Y-%d-%m"))

```

is returning the following:

```
[1] "2017-12-31" "2017-12-30" NA           NA   

```