儲存與匯出 xts 物件

個案研究:在 R 中分析城市時間序列資料

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

儲存為 rds

  • 使用 saveRDS() 與 readRDS()

    saveRDS(citydata, file = "citydata.rds")
    
  • 保留 xts 物件的時間索引

    readRDS("citydata.rds")
    
              pop pct_growth
1980-01-01 562994         NA
1990-01-01 574823   2.057851
2000-01-01 589141   2.430318
2010-01-01 617594   4.607072
個案研究:在 R 中分析城市時間序列資料

儲存為 csv

  • 使用 write.zoo() 與 read.zoo()

    write.zoo(citydata, file = "citydata.csv", sep = ",")
    
  • 需重新轉回 xts

citydata <- read.zoo("citydata.csv", sep = ",", header = TRUE)

as.xts(citydata)
              pop pct_growth
1980-01-01 562994         NA
1990-01-01 574823   2.057851
2000-01-01 589141   2.430318
2010-01-01 617594   4.607072
個案研究:在 R 中分析城市時間序列資料

一起來練習吧!

個案研究:在 R 中分析城市時間序列資料

Preparing Video For Download...