約 200000 行の大きなファイルがあり、zoo パッケージを使用してファイルをプロットし、日付、月、時間で切り捨てることができるようにファイルを取得したいと考えています。最初の列は修正ユリウス日で、2 番目の列は気温です。
助けていただければ幸いです。ファイルは次のようになります。
4812663507.000000,1.76438
4812663512.000000,1.65121
4812663517.000000,1.60362
4812663522.000000,1.51509
約 200000 行の大きなファイルがあり、zoo パッケージを使用してファイルをプロットし、日付、月、時間で切り捨てることができるようにファイルを取得したいと考えています。最初の列は修正ユリウス日で、2 番目の列は気温です。
助けていただければ幸いです。ファイルは次のようになります。
4812663507.000000,1.76438
4812663512.000000,1.65121
4812663517.000000,1.60362
4812663522.000000,1.51509
コメントから、時間はある種の MDJ 秒単位であるため、Gabor のヒントを使用して時間インデックスに変換できます。
library(zoo)
z <- read.zoo("myfile.dat", sep = ",",
FUN = function(x){as.POSIXct(x,origin='1858-11-17',tz='UTC')})
1858-11-17 は、http://en.wikipedia.org/wiki/Julian_dayごとの MJD エポックです。
または、オリジンを指定して秒数を追加することもできます。
z <- read.zoo("myfile.dat", sep = ",",
FUN = function(x){as.POSIXct('1858-11-17',tz='UTC')+x})
次に、時間のさまざまな粒度で集計されたデータが必要なようです。
plot(aggregate(z,cut(time(z),breaks='year' ),mean))
plot(aggregate(z,cut(time(z),breaks='quarter'),mean))
plot(aggregate(z,cut(time(z),breaks='month' ),mean))
plot(aggregate(z,cut(time(z),breaks='day' ),mean))
plot(aggregate(z,cut(time(z),breaks='hour' ),mean))
plot(aggregate(z,cut(time(z),breaks='6 min' ),mean))
plot(aggregate(z,cut(time(z),breaks='min' ),mean))
plot(aggregate(z,cut(time(z),breaks='10 sec' ),mean))
plot(aggregate(z,cut(time(z),breaks='sec' ),mean))