Skip to content

Instantly share code, notes, and snippets.

@jokergoo
Created July 19, 2013 19:14
Show Gist options
  • Save jokergoo/6041648 to your computer and use it in GitHub Desktop.
Save jokergoo/6041648 to your computer and use it in GitHub Desktop.
build.position.index = function(x, by = 5) {
segment = round((x/(10^by)))*10^by
se = unique(segment)
mat = matrix(nrow = length(se), ncol = 2)
for(i in seq_along(se)) {
mat[i, ] = range(which(segment == se[i]))
}
list(mat = mat, segment = se, by = 10^by)
}
get.position.index = function(x, index) {
i = round(x / index$by)
index$mat[i+1, ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment