R - 将数据帧转换为时间序列 [英] R - Transform Data frame to Time Series

查看:34
本文介绍了R - 将数据帧转换为时间序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有谷歌股票数据.它有两列 Date(Daily Data) 和 Close,即 Google 关闭索引.

I have a Google stock data. It has two columns Date(Daily Data) and Close i.e. Google closing index.

Date    Close
10/11/2013  871.99
10/10/2013   868.24
10/9/2013    855.86
10/8/2013   853.67
10/7/2013   865.74
10/4/2013   872.35
10/3/2013   876.09
10/2/2013   887.99
10/1/2013   887
9/30/2013   875.91
9/27/2013   876.39
9/26/2013   878.17
9/25/2013   877.23
9/24/2013   886.84

和它的 csv 格式,我通过 read.csv 读取它,它返回数据框对象.当我尝试将其转换为时间序列/ts() 对象时,它返回不需要的数字.

and its in csv format and I read it through read.csv which return data frame object. When I tried to transform it into timeseries / ts() object, it returns unwanted numbers.

请帮我将数据框转换为 ts() 对象.

Please help me to convert data frame into ts() object.

提前致谢.

推荐答案

我建议使用 xts 而不是 ts 因为它有很多功能,特别是对于金融时间序列.如果您的数据在 data.frame DF 中,那么您可以将其转换为 xts 如下

I suggest using xts instead of ts as it has lot of functions especially for financial time series. If your data is in data.frame DF then you can convert it to xts as follows

xts(DF$Close, as.Date(DF$Date, format='%m/%d/%Y')

这篇关于R - 将数据帧转换为时间序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆