开始使用免费开始使用

创建零宽度且规则的 xts 对象

为了从不规则数据集创建规则数据,首先需要生成一段规则的日期时间序列,覆盖不规则数据集的全部日期。"规则"的日期时间序列指的是时间点等间隔。

在本练习中,您将使用 irregular_xts 对象来创建一个具有规则日频索引的零宽度 xts 对象。零宽度的 xts 对象只有日期时间索引,没有数据列。

本练习是课程的一部分

在 R 中导入与管理金融数据

查看课程

练习说明

  • 使用 start() 函数创建名为 start_date 的对象。
  • 使用 end() 函数创建名为 end_date 的对象。
  • 使用 seq() 函数创建名为 regular_index 的对象,其中包含从 start_dateend_date 按天的日期时间序列。
  • 使用 xts() 构造函数创建一个零宽度的 xts 对象。将其存入 regular_xts

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Extract the start date of the series


# Extract the end date of the series


# Create a regular date sequence
regular_index <- seq(___, ___, by = "___")

# Create a zero-width xts object
regular_xts <- xts(, order.by = ___)
编辑并运行代码