1

data次のようなデータフレームがあります。

dim(data)
# [1] 66955      2
library(chron)
data <- structure(list(`Date-Time` = structure(c(11320.6592476852,
  11320.6661921296, 11324.3958564815, 11324.4022569444),
  format = structure(c("y/m/d", "h:m:s"), .Names = c("dates", "times")),
  origin = structure(c(1, 1, 1970), .Names = c("month", "day", "year")),
  class = c("chron", "dates", "times")), Price = c(14.8125, 14.875,
  14.9375, 14.9375)), .Names = c("Date-Time", "Price"),
  row.names = 18620:18623, class = "data.frame")

の最初の列dataは、クラス "chron" "dates" "times" です。日時の形式は (yy/mm/dd h:m:s) です。data[,2]関数を使用するために xts オブジェクトに変換しようとしていますmakeReturns

私は試した:

library(xts)
as.xts(data[,2] , order.by=data[,1], format=c(dates="y/m/d", times="h:m:s"))

しかし、これにより次のことがわかります(上の行について):

                       [,1]
(NA NA)             14.8125
(NA NA)             14.8750
(01/01/02 09:30:02) 14.9375
(01/01/02 09:39:15) 14.9375

つまり、最初の 2 行 (日時形式 (00/12/29 15:49:19) および (00/12/29 15:59:19)) を yy/mm/dd として認識しません。 (および h:m:s)。実際、最初の 2 行の年は "00" (2000) であり、変換されませんが、3 行目と 4 行目の年は "01" (2001) であり、彼はこれを変換しますが、日または月。

元の形式が変わらないように、すべてがその形式に変換されていることを確認するにはどうすればよいですか? でいくつかのバリエーションを試しましたformat=" "が、何も機能しませんでした。

4

1 に答える 1