0

I have a large file with about 200000 lines and I'd like to get the file in a way that I can use the zoo package to plot the file and to truncate by date,month and time. The first column is the modified julian date and the second is temperature.

I'd appreciate any help. The file looks like:

4812663507.000000,1.76438
4812663512.000000,1.65121
4812663517.000000,1.60362
4812663522.000000,1.51509
4

1 回答 1

1

从评论中,时间以某种 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)) 
于 2015-02-06T05:13:23.567 回答