I've two dataframes, Data
and quantiles
. Data
has a dimension of 23011 x 2
and consists of columns "year"
and "data"
where year are the sequence of days from 1951:2013. The Quantiles
df has a dimension of 63x2
consists of columns "year"
and "quantiles"
, where year are 63 rows, ie. 1951:2013
.
I need to compare Quantile
df against the Data
df and count the sum of data values exceeding the quantiles value for each year. For that, I'm using ddply
in this manner :
ddply(data, .(year), function(y) sum(y[which(y[,2] > quantile[,2]),2]) )
However, the code compares only against the first row of quantile and is not iterating over each of the year against the data df.
I want to iterate over each year in quantile
df and calculate the sum of data exceeding the quantile
df in each year.
Any help shall be greatly appreciated.
The example problem -
quantile
df is here
and Data
is pasted here
The quantile
df is derived from the data
, which is the 90th percentile data
df exceeding value 1
quantile = quantile(data[-c(which(prcp2[,2] < 1)),x],0.9)})