保存与导出 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 中分析城市时间序列数据

Let's practice!

案例研究:在 R 中分析城市时间序列数据

Preparing Video For Download...