【问题标题】:Storing Sys.time() in a data frame将 Sys.time() 存储在数据框中
【发布时间】:2019-06-23 19:28:54
【问题描述】:

我目前正在尝试存储通过包“tseries”提取股票报价的循环的每一步的时间。不幸的是,当尝试将Sys.time() 存储在我的数据框中时,它不会存储时间而是一堆数字。 首先,我认为这可能是class() 的问题,因此尝试使用as.POSIXct() 导致以下错误: "as.POSIXct.numeric(test[, 2]) 中的错误:必须指定'origin'"

这段代码重现了我的问题:

Loop <- c(rep(NA,10))
Time <- c(rep(NA,10))
test <- cbind(Loop,Time)

for(i in 1:length(test[,1])){
  test[i,1] <- i
  test[i,2] <- Sys.time()
}

as.POSIXct(test[,2])

如果有任何提示可以让我解决此问题,我将不胜感激。

【问题讨论】:

    标签: r for-loop


    【解决方案1】:

    指定起始时间?

    as.POSIXct(test[,2], origin = "1970-01-01", tz = "UTC")
    

    【讨论】:

      猜你喜欢
      • 2015-09-22
      • 2013-05-06
      • 2018-03-20
      • 2018-10-31
      • 2020-01-26
      • 1970-01-01
      • 1970-01-01
      • 2017-09-08
      • 2020-04-16
      相关资源
      最近更新 更多