生成每月平均值
本练习是课程的一部分
案例研究:在 R 中分析城市时间序列数据
练习说明
- 使用
split()从temps_xts_2对象的mean列生成按月的列表。请将周期(参数f)指定为"months"。 - 使用
lapply()计算"均值的均值",即每个月的平均mean气温。 - 使用
as.xts()生成一个新的 xts 对象,包含 2010 至 2015 年波士顿的每月平均气温。为此,您需要将每月的mean_of_means数据与每月的index对象组合起来。 - 最后,确认新的
temps_monthly对象与flights_xts的时长与周期性一致。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Split temps_xts_2 into separate lists per month
monthly_split <- split(___$___ , f = "___")
# Use lapply to generate the monthly mean of mean temperatures
mean_of_means <- lapply(___, FUN = ___)
# Use as.xts to generate an xts object of average monthly temperature data
temps_monthly <- as.xts(as.numeric(___), order.by = ___)
# Compare the periodicity and duration of your new temps_monthly and flights_xts
periodicity(___)
periodicity(___)