将 data.frame 转换为 xts 对象并保留类型 [英] Convert data.frame to xts object and preserve types
问题描述
有没有办法从 data.frame 创建 xts 对象并保留数据类型?我的数字正在转换为字符.2009 年的这篇文章建议将列合并到现有的 xts 中:http:///r.789695.n4.nabble.com/as-xts-convert-all-my-numeric-data-to-character-td975564.html
Is there a way to create an xts object from a data.frame and preserve data type? My numerics are being converted to character. This post from 2009 suggests merging columns into an existing xts: http://r.789695.n4.nabble.com/as-xts-convert-all-my-numeric-data-to-character-td975564.html
不清楚这是否是唯一的方法.对于大型数据帧来说,似乎有点麻烦和麻烦.我认为开箱即用的 xts 会尊重数据类型.
It wasn't clear whether that is the ONLY way to do this. Seems a bit of a hack and cumbersome for large data frames. I would think out-of-the-box xts would respect the datatypes.
推荐答案
不,你不能.xts/zoo 对象是一个带有索引属性的矩阵,你不能在矩阵中混合类型.
No, you can't. xts/zoo objects are a matrix with an index attribute and you can't mix types in a matrix.
我们已经考虑过创建一个 xts-data.frame 类,但 xts 的主要关注点是速度和内存效率.data.frames 的速度和内存效率不高,因此这不是优先事项.
We've considered creating an xts-data.frame class but a primary concern of xts is speed and memory efficiency. data.frames are not speed and memory efficient, so this hasn't been a priority.
这篇关于将 data.frame 转换为 xts 对象并保留类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!