将数据框转换为xts [英] Converting a data frame to xts

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

问题描述

我正在使用as.xts() - 方法将数据帧转换为xts对象。这是我的输入数据框q:

I'm trying to convert a data frame to xts object using the as.xts()-method. Here is my input dataframe q:

q
                      t x  
1  2006-01-01 00:00:00  1  
2  2006-01-01 01:00:00  2  
3  2006-01-01 02:00:00  3

str(q)
    'data.frame':   10 obs. of  2 variables:
 $ t: POSIXct, format: "2006-01-01 00:00:00" "2006-01-01 01:00:00" "2006-01-01 02:00:00" "2006-01-01 03:00:00" ...  
 $ x: int  1 2 3 4 5 6 7 8 9 10

结果是:

> as.xts(q)
Error in as.POSIXlt.character(x, tz, ...) : 
  character string is not in a standard unambiguous format

这是我可以想到的最简单的例子,所以非常令人沮丧的是没有得到它的工作...任何帮助是赞赏!

This is the simplest example I can think of, so it's quite frustrating not getting it to work... Any help is appreciated!

推荐答案

这是清楚的记录--- xts 动物园对象是通过提供两个参数,向量矩阵携带数据和 Date POSIXct chron ,...提供时间信息(或在动物园订购)。

This is clearly documented --- xts and zoo objects are formed by supplying two arguments, a vector or matrix carrying data and Date, POSIXct, chron, ... type supplying the time information (or in the case of zoo the ordering).

所以做一些类似

 qxts <- xts(q[,-1], order.by=q[,1])

你应该是设置。

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

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