문제

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”
도움이 되었습니까?

해결책

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

births <- xts(births, dates$Month)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top