I have this integer vector:
m <- 10
n <- 1000
index <- sample(seq_len(n), m)
I want to extend index, by including all integers whose distance from one of the values in index is no greater than 10, and eliminate duplicates. Duplicates are not very likely, with the current values of n and m, but better safe than sorry, and anyway the solution must work with generic values of n and m, with m<n.
Right now I do the following:
library(purrr)
index <- unique(sort(unlist(map(index, function(x) seq(x - 10, x + 10)))))
This works, but it's not exactly very readable. Any better ideas?