產生每月平均值
本練習屬於課程
個案研究:在 R 中分析城市時間序列資料
練習說明
- 使用
split()以temps_xts_2物件中的mean欄為來源,依月份產生清單。請將期間(引數f)指定為"months"。 - 使用
lapply()計算「mean 的平均」,也就是每個月的平均 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(___)