This returns NA
instead of a Date object 2012-01
.
as.Date(
x = "2012-01",
format = "%Y-%m"
)
Why does this return NA
and what must I change to make it return a Date object representing January 2012?
Dates need to have a year, month, and day component. Assuming you were OK with the first of the month representing a given month, you could use:
x <- "2012-01"
d <- paste0(x, "-01")
as.Date(d, format="%Y-%m-%d")