I have a csv file with 2 coloumns-price and date.I am trying to do time series forecasting and for that I need to convert the date coloumn to date-time class. Presently the class of Date coloumn is NULL.I tried to convert it to character format,but its not working.Also,is there a way that I can do this directly in csv file in excel?
wti.daily <- read.csv(file="wti.csv",stringsAsFactors = FALSE)
> wti.daily$date <- as.Date(as.character(wti.daily$date))
Error in `$<-.data.frame`(`*tmp*`, date, value = numeric(0)) :
replacement has 0 rows, data has 1598
> class(wti.daily$date)
[1] "NULL"
> wti.daily$Date = as.Date(wti.daily$date)
Error in as.Date.default(wti.daily$date) :
do not know how to convert 'wti.daily$date' to class “Date”
> wti.daily$date <- as.Date(wti.daily$date,format = "%m/%d/%y")
Error in as.Date.default(wti.daily$date, format = "%m/%d/%y") :
> head(wti.daily)
Date Price
1 02-01-2012 98.83
2 03-01-2012 102.96
3 04-01-2012 103.22