Skip to Content
R 语言经典实例(原书第 2 版)
book

R 语言经典实例(原书第 2 版)

by J.D. Long, Paul Teetor
June 2020
Beginner to intermediate
522 pages
9h 6m
Chinese
China Machine Press
Content preview from R 语言经典实例(原书第 2 版)
时间序列分析
411
14.1 表示时间序列
14.1.1 问题
需要一个可以表示时间序列数据的 R 数据结构。
14.1.2 解决方案
我们推荐使用 zoo xts 包。它们定义了时间序列的数据结构,包含许多用于处理时
间序列数据的有用函数。以如下方式创建一个 zoo 对象,其中 x 是向量、矩阵或数据
框,dt 是存储相应日期或日期时间的向量:
library(zoo)
ts <- zoo(x, dt)
创建一个 xts 对象:
library(xts)
ts <- xts(x, dt)
使用 as.zoo as.xts 在时间序列数据的表示方式之间进行转换:
as.zoo(ts)
ts 转换为 zoo 对象
as.xts(ts)
ts 转换为 xts 对象
14.1.3 讨论
R 具有至少八种不同的用于表示时间序列的数据结构实现。我们还没有一一尝试,但 zoo
包和 xts 包是处理时间序列数据的优秀的包,并且比我们尝试的其他数据分析包更好。
这两种表示数据的方法都假设你有两个向量:数据观测向量和相应的观测日期或时间向
量。zoo 函数将它们组合成一个 zoo 对象:
library(zoo)
#>
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#>
#> as.Date, as.Date.numeric
x <- c(3, 4, 1, 4, 8)
dt <- seq(as.Date("2018-01-01"), ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

Aurélien Géron
大规模数据分析和建模:基于 Spark 与 R

大规模数据分析和建模:基于 Spark 与 R

Javier Luraschi, Kevin Kuo, Edgar Ruiz
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey

Publisher Resources

ISBN: 9787111656814