Skip to content

Instantly share code, notes, and snippets.

@brezniczky
Last active July 16, 2016 14:34
Show Gist options
  • Save brezniczky/cdf38c8cb06d9c4272ab to your computer and use it in GitHub Desktop.
Save brezniczky/cdf38c8cb06d9c4272ab to your computer and use it in GitHub Desktop.
Blogger code #2 (filter, snippet #2)
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