r - Generating yearly frequency plot from multi-year data -


i have hourly wind speed data in following format

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 

which starts data point recorded once in 3 hours data point 3 times in single hour year 2002 2012 below:

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 

i trying create yearly frequency plots showing speed vs no.of.hours using r. tried use histograms number of points unequal , doesn't represent no.of hours. how can solved?

note: dir value not used, * considered na

you estimate speed every hour using approx() function, use estimated hourly speeds create histograms. example, assuming data frame called df, ...

library(lubridate) # date/time class posixct df$dt2 <- ymd_hm(df$dt)  # create new data frame, everyhour, every hour between first , last in df everyhour <- data.frame(dt2=seq(ceiling_date(min(df$dt2), "hour"), floor_date(max(df$dt2), "hour"), 3600), forhist=true)  # merge observed data everyhour data df2 <- merge(df, everyhour, all=true) # set missing forhist false df2$forhist[is.na(df2$forhist)] <- false # define year df2$year <- year(df2$dt2) # estimate speed 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) 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -