[R] aggregating using a non-summary function?
Sherri Heck
sheck at ucar.edu
Wed Aug 19 01:09:00 CEST 2009
Dear all-
I have a data set that looks as follows (data are taken every 5 minutes):
LST in mph Deg DegF DegF2 % volts Deg mph2 w/m2
0905010000 -999 7.5 259.3 33.0 -999 41.5 -999 -999 9.1 0.2
0905010005 -999 11.0 261.2 33.1 -999 42.6 -999 -999 18.2 0.2
0905010010 -999 8.9 252.5 33.4 -999 41.6 -999 -999 12.4 0.2
0905010015 -999 9.1 265.9 33.2 -999 41.8 -999 -999 11.7 0.2
I am able to calculate the hourly average of "mph" over a span of 3 months with the following code:
z <- read.zoo("SPL summer 2009.txt", header = TRUE, na.strings = -999,
format = "%y%m%d%H%M", FUN = as.chron,
colClasses = c("character", rep("numeric", 10)))
mph <- z[months(time(z)) %in% c("May", "Jun", "Jul"),]
ww <- aggregate(z$mph, trunc(time(z), "hour"), mean)
but, i need to take the hourly average (spanning the same three months) of the directional degrees (Deg) in order to use that data to create a wind rose. I was planning to get the hourly avg step by step , i.e. converting to radians, taking sins, etc, but "aggregate" seems to only use summary-type functions. I have been playing around with "daply", which seems to accept other functions, but am not sure how to convert the time/date stamp within it.
I would appreciate it if anyone could point me in the right direction-
sherri
More information about the R-help
mailing list