After looking at Why does mapply not return date-objects?, I still cannot fix my problem.
The problem:
I have a matrix of date values and I want to convert them to date objects by the following function:
convert_endDate <- function(e){
d <- paste(e[1], e[2],e[3], sep = "-")
print(as.Date(strptime(d, format = "%Y-%m-%d")))
return(as.Date(strptime(d, format = "%Y-%m-%d")))
}
apply(end, 1,convert_endDate)
However, it always returns numbers to me:
[1] 16276 15850 14085 13569 13293 12473 12046 11316 10950 10950
Now, how can I convert this to Dates ???
The data matrix end
is below:
eyr em
[1,] 2014 7 25
[2,] 2013 5 25
[3,] 2008 7 25
[4,] 2007 2 25
[5,] 2006 5 25
[6,] 2004 2 25
[7,] 2002 12 25
[8,] 2000 12 25
[9,] 1999 12 25
[10,] 1999 12 25