1

我有以下格式的每小时风速数据

DT,DIR,SPEED                                                                                                                               
2002/01/01 00:00,***,0.0
2002/01/01 03:00,360,0.89408
2002/01/01 06:00,070,4.91744
2002/01/01 09:00,050,4.4704
2002/01/01 15:00,050,2.2352
2002/01/01 18:00,050,3.12928
2002/01/01 21:00,020,0.89408

从 2002 年到 2012 年从每三个小时记录一次的数据点开始到在一个小时内记录三次的数据点,如下所示:

2012/12/31 00:00,***,0.0
2012/12/31 00:10,***,0.0
2012/12/31 00:40,***,0.0
2012/12/31 01:10,***,0.0
2012/12/31 01:40,***,0.0
2012/12/31 02:10,***,0.0
2012/12/31 02:40,***,0.0
2012/12/31 03:00,***,0.0
2012/12/31 03:10,310,2.2352
2012/12/31 03:40,060,4.02336
2012/12/31 04:40,060,3.12928
2012/12/31 05:10,070,4.91744

我正在尝试使用 R 创建显示 SPEED 与 No.of.Hours 的年度频率图。我尝试使用直方图,但点数不相等,当然不能完全代表小时数。如何解决?

注意:不使用 DIR 值,也将*视为 NA

4

1 回答 1

0

您可以使用该approx()函数估计每小时的速度,然后使用这些估计的每小时速度来创建直方图。例如,假设您的数据框被调用df,...

library(lubridate)
# date/time as class POSIXct
df$DT2 <- ymd_hm(df$DT)

# create a new data frame, everyhour, with every hour between the first and the last in df
everyhour <- data.frame(DT2=seq(ceiling_date(min(df$DT2), "hour"), floor_date(max(df$DT2), "hour"), 3600), FORHIST=TRUE)

# merge the observed data with the everyhour data
df2 <- merge(df, everyhour, all=TRUE)
# set missing FORHIST to FALSE
df2$FORHIST[is.na(df2$FORHIST)] <- FALSE
# define year
df2$YEAR <- year(df2$DT2)
# estimate speed for everyhour
df2$estSPEED <- approx(x=df2$DT2, y=df2$SPEED, xout=df2$DT2, method="linear")$y

# plot annual histograms of hourly speeds
suy <- sort(unique(df2$YEAR))
par(mfrow=n2mfrow(length(suy)), mar=c(3, 3, 2, 1), oma=c(2, 2, 0, 0))
for(i in seq(suy)) {
    sel <- df2$YEAR==suy[i] & df2$FORHIST==TRUE
    hist(df2$estSPEED[sel], xlab="", ylab="", main=suy[i])
    }
mtext("Speed", side=1, outer=TRUE)
mtext("Frequency", side=2, outer=TRUE)
于 2013-05-10T14:22:20.923 回答