【问题标题】:export XTS to CSV, with separate columns将 XTS 导出为 CSV,使用单独的列
【发布时间】:2019-05-12 22:54:22
【问题描述】:

我目前有一些时间序列数据,它是 XTS 形式的。这是下面的一部分。

head(dbt)
                    NSW1.Price     Coal
2018-01-01 00:30:00      91.86 71.29267
2018-01-01 01:00:00      88.83 71.25520
2018-01-01 01:30:00      73.62 71.22649
2018-01-01 02:00:00      71.49 71.18284
2018-01-01 02:30:00      69.27 71.14081
2018-01-01 03:00:00      68.44 71.10430

我正在尝试将其导出到 CSV 文件,但是当我这样做时,它不会导出到单独的列中。这就是我尝试导出时发生的情况。

我使用的代码是

write.zoo(dbt,file="export.csv",index.name="okay",row.names=FALSE,col.names=TRUE)

【问题讨论】:

    标签: r csv time-series xts zoo


    【解决方案1】:

    你需要sep=","

    直接来自write.zoo的帮助:

    read.zoo and write.zoo are convenience functions for reading and writing "zoo"
    series from/to text files. They are convenience interfaces to read.table and
    write.table, respectively.
    
    
    ... further arguments passed to read.table, write.table, or read.zoo, respectively.
    

    因此,这应该可行:

    write.zoo(dbt,file="export.csv",index.name="okay",row.names=FALSE,col.names=TRUE,sep=",")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-08
      • 2018-11-04
      • 2015-11-06
      • 2021-10-24
      • 1970-01-01
      • 2016-07-01
      • 2018-05-17
      • 2016-04-25
      相关资源
      最近更新 更多