Pergunta

births and dates are from same file and share same length. format of dates seems to be good. But xts cannot recogize it as date,why?! Thanks for your help!

dates <- read.xlsx("TimeSeriesCourseworkData.xls", 1,colIndex=1,as.data.frame=TRUE)
dates

        Month
1  2009-01-01
2  2009-02-01
3  2009-03-01
4  2009-04-01
............

26 2011-02-01
27 2011-03-01
28 2011-04-01
29 2011-05-01
30 2011-06-01

births <- xts(births, order.by = dates) 
# Error in xts(births, order.by = dates) : 
# order.by requires an appropriate time-based object

births <- xts(births, order.by = as.Date(dates))
# Error in as.Date.default(dates) : 
# do not know how to convert 'dates' to class “Date”
Foi útil?

Solução

dates is a 1-column data.frame. as.Date and xts' order.by argument require vectors.

births <- xts(births, dates$Month)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top