You can do this in more ways than one in R. The simplest way would be to use %in%
to check which of your values are not in the list of values you want to remove. For example:
> todos <- 1:10 #Seus dados, números de 1 a 10
> excluir <- c(2,3,5,7) #Valores que serão removidos
> todos[!todos %in% excluir] #Faz um subset dos valores não-contidos em excluir
[1] 1 4 6 8 9 10
This approach does not seem to be heavy even for this amount of data, but another alternative would be to use filter
of dplyr
, which would look like this:
> library(dplyr)
> df <- data.frame(todos) #Transformando em dataframe
> df %>% filter(! todos %in% excluir)
todos
1 1
2 4
3 6
4 8
5 9
6 10
If you are going to nest other commands, dplyr
may be a good alternative, otherwise there is no need to load the package just for that.
This would remove your unwanted values, but I do not think it would result in an improvement in data manipulation since you would remove only 0.2% of the rows. It may be possible to improve the code at other points to improve the steps that are really slow, rather than reducing the size of the data.