将 ts(时间序列)对象转换为 R 中的向量
我需要在不接受 ts 对象的向量上使用函数。我正在尝试将其转换为普通的旧向量,但我似乎无法弄清楚。我用谷歌搜索了一下,但大多数人都在尝试将数据类型转换为 ts 对象。我想走另一条路。任何帮助将不胜感激。
I need to use a function on a vector that does not take a ts object. I'm trying to convert it to a plain old vector but I just can't seem to figure it out. I googled around but mostly people are trying to convert data types into ts object. I want to go the other way. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AP1 是一个与 AP 具有相同值和长度的向量。该类现在是数字而不是 ts,这在一定程度上意味着索引不再是某种日期时间对象,而只是普通的顺序整数。
因此,对于OP中的具体问题,上面的两个片段中的任何一个都会“将[a ts对象]转换为普通的旧向量”
如果您需要对索引而不是值,或者除了值之外,即从 Date 对象到数字,您可以这样做:
AP1 is a vector with the same values and length as AP. The class is now numeric instead of ts, which means, in part that the indices are no longer some sort of date-time object but just ordinary sequential integers.
So w/r/t the specific question in the OP, either of the two snippets above will "convert [a ts object] to a plain old vector"
If you need to do the same thing with the indices rather than, or in addition to, the values--ie, from Date objects to numeric, you can do that like so: