2

I have a time-series dataset in csv format. The monthly data is from 4/1/1953 to 6/1/2017. I want to convert this into an xts object in R. I used the following codes to import the dataset and then convert into xts. However, after the conversion, my time index starts from 2019-01-01. I have attached a snippet of my xts object here for your convenience. 1: https://i.stack.imgur.com/URyzb.png

data<-read.csv("10year_3month_treas_Bond_eq_spread.csv", stringsAsFactors = F)
data$DATE=as.Date(data$DATE,"%m/%d/%y")
data<-as.xts(data[,-1], order.by = data[,1])

I will be grateful if you could help me fix this.

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
Anup
  • 239
  • 2
  • 11

1 Answers1

0

Joshua Ulrich,

You may have probably fixed the issue already but I am hoping my answer would be helpful for someone else. When specifying the year in R, use "y" for 2-digit year such as 99, 05 whereas "Y" for 4-digit year such as 1999, 2005. The code above may be fixed by replacing date format "%m/%d/%y" with "%m/%d/%Y."

Have a great day!