> stockprices <- data.frame(prices=c(1.1,2.2,3.3),
timestamps=c('2011-01-05 11:00','2011-01-05 12:00','2011-01-05 13:00'))
> stockprices
prices timestamps
1 1.1 2011-01-05 11:00
2 2.2 2011-01-05 12:00
3 3.3 2011-01-05 13:00
You can convert to xts time series thus:
> require(xts)
> stockprices.ts <- xts(stockprices$prices, order.by=as.POSIXct(stockprices$timestamps))
> stockprices.ts
[,1]
2011-01-05 11:00:00 1.1
2011-01-05 12:00:00 2.2
2011-01-05 13:00:00 3.3
实际上上面回复帖子创建的不是ts类,而是xts类。ts比较适合相同间隔的月度数据
推荐两篇关于zoo和xts的经典介绍文章