I have data for stocks, that I have shortened the time frame of in R, but when I go to graph it, the plot still shows blank values and dates I have removed. I also was trying to get R to read my date column as dates but it was not working. I noticed the problem with the dates when I was trying to run my ACF's and linear models.
> sp<-read.csv(file="~/Desktop/SP500.csv", header=T, sep=",",check.names=FALSE)
> sfshort=sp[1428:2049,]
> plot(sfshort)
> sfshort
Date Value
1428 2005-01-07 1186.19
1429 2005-01-14 1184.52
1430 2005-01-21 1167.87
1431 2005-01-28 1171.36
1432 2005-02-04 1203.03
1433 2005-02-11 1205.30
1434 2005-02-18 1201.59
1435 2005-02-25 1211.37
1436 2005-03-04 1222.12
1437 2005-03-11 1200.08
1438 2005-03-18 1189.65
1439 2005-03-24 1171.42
1440 2005-04-01 1172.92
1441 2005-04-08 1181.20
1442 2005-04-15 1142.62
First few points are listed above. Here is the code that I used to try and convert the date column. I have used this in older projects so I am not sure why it is not working.
sfshort <- as.Date(spfshort$Date, "%m/%d/%y")
The date in my excel file was listed as MM/DD/YYYY. Here is what I was seeing when I went to run the linear model.
> lm(sfshort$Value~sfshort$Date)
Call:
lm(formula = sfshort$Value ~ sfshort$Date)
Coefficients:
(Intercept) sfshort$Date2005-01-14 sfshort$Date2005-01-21
1186.19 -1.67 -18.32
sfshort$Date2005-01-28 sfshort$Date2005-02-04 sfshort$Date2005-02-11
-14.83 16.84 19.11