I'm trying to do a time series analysis. Before that i need to index my date which is given in a YYYYMM format. I want to index it to to in-sample and out-of-sample analysis. I'm unable to index it.
I find similar questions in this platform but nothing seems to work in R. I tried using as.Date(), but unsuccessful so far.
Date <- c("198001","198002","198003","198004","198005")
X1 <- c("10", "20", "30", "40", "50")
X2 <- c("60", "70", "80", "90", "100")
df2 <- data.frame(Date,X1,X2)
df2
df2$Date <- as.Date(df2$Date, format = "%Y %m")
df2
But I'm getting under the Date variable
Expected Result:
X1 X2
198001 10 60
198002 20 70
198003 30 80
189804 40 90
189005 50 100