Last active
July 16, 2016 14:34
-
-
Save brezniczky/cdf38c8cb06d9c4272ab to your computer and use it in GitHub Desktop.
Blogger code #2 (filter, snippet #2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
quicker.count = function(data, window.width = default.window.width) { | |
# ... | |
# start and do the counting | |
for(i in 2:n.positions) { | |
# the value leaving the window is the first item in the | |
# previous window, i.e. data[i - 1] | |
old.data.idx = x[i - 1] + 1 | |
frequency[old.data.idx] = frequency[old.data.idx] - 1 | |
# the value entering the window is the last item in the | |
# current window | |
new.data.idx = x[i + window.width - 1] + 1 | |
frequency[new.data.idx] = frequency[new.data.idx] + 1 | |
ans[i] = count.positives(frequency) | |
} | |
# ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment