Create a sequence of numbers excluding specific numbers

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 effective way to do this in R?

Thank you very much!

+4
source share
3 answers

Using setdiff :

 setdiff(1:85,seq(1,85,5)) [1] 2 3 4 5 7 8 9 10 12 ... 
+5
source

If the numbers you want to exclude cannot be generalized, @HongOoi or @James answers is the way to go. But if they can be described by some math test, Filter will be more efficient.

 Filter(function(x) x %% 5 != 1, 1:85) 
+5
source
 (1:85)[-seq(1, 85, 5)] 

or is it too obvious / ineffective?

+3
source

Source: https://habr.com/ru/post/1488282/


All Articles