aggregate - Find value relative to mean for particular Day of Year in R -


i'm working meteorology data in r, , conceptually, i'm trying find out how day above/below average. this, want separate day of year, find average doy (e.g. average january 1 temperature?), , compare every date (e.g january 1, 2014 anomalously warm, how much?)

i can find 'mean' table every day of year using aggregate:

head(data)           x       date 1  5.072241 1970-01-01 2  6.517069 1970-01-02 3  4.413654 1970-01-03 4 11.129351 1970-01-04 5  9.331630 1970-01-05  library(lubridate) temp = aggregate(data$x, list(yday(data$date)), mean) 

but i'm stuck how use aggregated table compare original data.frame, see how x @ 1970 jan 1 relates average jan 1 x.

we can remove 'year' part sub ('monthday'). use ave if mean variable needs created grouped 'monthday'.

data$monthday <- sub('\\d+-', '', data$date) data$mean <- with(data, ave(x, monthday)) 

then, can compare 'x' variable, example

data$rel_temp <- with(data, x/mean) 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -