I have a R dataframe which have sequence of dates. I want to create a dataframe from the existing one which consists of one month prior dates. For example let x be the initial dataframe
x = data.frame(dt = c("28/02/2000","29/02/2000","1/03/2000","02/03/2000"))
My required dataframe y would be
y = c("28/01/2000","29/01/2000","1/02/2000","02/02/2000")
The list is quite big so I don't want looping. I have created a inline function which works fine when I give individual dates.
datefun <- function(x) seq(as.Date(strptime(x,format = "%d/%m/%Y")), length =2, by = "-1 month")[2]
datefun("28/02/2000") gives "28/01/2000" as an output
But while I use it inside R apply it gives random numerical values.
apply(x,1,function(x) datefun(x))
The output for this is
[1] 10984 10985 10988 10989
I don't know from where these numbers are getting generated, am I missing something.