Conversion of Data Class from Factor to TS

r
date

#1

Hello All,

I am trying to plot ts stock price for PNB (Nifty Index) over a period of 1 year in order to study the patterns. Attached is the data for stock Price in CSV format.
But when I am trying to convert the class of this data from CSV file using zoo (xts) package,

Note: xts is subset of zoo package.

d<-xts(f$Close.Price,order.by=as.Date(f$Date),format="%m/%d/%y")
Error in charToDate(x) :
character string is not in a standard unambiguous format
where f is the dataframe which is the reading the .csv file

I have also tried with date variable with the following command and gives me below error,

s<-as.Date(f$Date, format = “%d/%m/%Y”)
s
[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[29] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[57] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[85] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[113] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[141] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[169] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[197] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[225] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[253] NA

I am getting NA for the dates.
In other words, I am not able to convert the class of f$Date into “ts” class. I have tried multiple blogs (especially Stackover flow) but none of them have the explanation.
Please help me to convert the data into ts format by using zoo or xts.SP.csv (10.1 KB)


#2

@richie31 - You can look into this link for reference .It has similar example which you are trying.

Hope this helps!

Regards,
Hinduja


#3

Thank you, I am looking into that.
Please advice me on some test book with Numerical examples on Time Series Analysis(ARMA, ACF, PACF, and Non Stationary Analysis) with R.

I have gone through number of books, but most of them are two much theoretical and does not contain numerics with R.

Please advice. Once again thanks a lot for your help. I am looking into the code…

Thank You


#4

I checked the code, but that is converting the entire bunch of dates into number. But I tweaked it and its working. Thanks a lot.

As of now I am using package “Lubridate” in order to convert them into ts. This package is good and easily converts it to dmy/mdy format.

Thanks a lot.