I would like to create a sequence of 1:85, but excluding the numbers in seq(1,85,5). So like this:
2 3 4 5 7 8 9 10 12 13 etc..
What would be an efficient way to do this in R?
Many thanks!
Using setdiff
:
setdiff(1:85,seq(1,85,5))
[1] 2 3 4 5 7 8 9 10 12 ...
If the numbers you want to exclude can't be generalized, @HongOoi or @James answers are the way to go. But if they can be described by some mathematical test, Filter
would be more efficient.
Filter(function(x) x %% 5 != 1, 1:85)
(1:85)[-seq(1, 85, 5)]
or is that too obvious/inefficient?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With