I am looking for a way to count observations like here but with the ability to change criteria according to the specific observation (moving count).
For example - count the number of observations of mag (from the last 50) which are greater than the specific observation of mag. The code I have:
rollapplyr(zoo(mag),50,function(i){sum(mag>i)},partial=T,by.column=F,fill=NA))
This code takes the average mag of the 50 last observations and calculates the number of observations above that average (in the whole data-set).
What am I missing ?
Maybe using rollapply is not the case here ?
To sum it up:
1. count according to specific row value
2. count only in the 50 last observations (and not the whole data-column).
iin your function is the "windowed" data andmag, as you said, in the whole column. So the code definitely does not what you say above. Also, there is no sample data and expected output, please add it if you can. - m-dz