You can do this more than one way in R. The simplest way would be to use the %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 me to be heavy even for this amount of data, but another alternative would be to use the filter
of dplyr
, that 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’re nesting other commands, the 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 don’t think it would result in an improvement in data handling as you would only remove 0.2% of the lines. It may be possible to improve the code at other points to improve the steps that are actually slow, rather than reducing the size of the data.
Thank you for your answer! I did two tests with the first possibility, but for some reason it didn’t work. Try 1 I read my file which is a table in a variable. Then read the list of values you want to keep in another variable. , and then the command === all[! all %in% delete] but it didn’t work Try 2 Then I separated the file into columns, that is, I took the inter-column approach, but it didn’t work either. The second possibility results in the following error: Error in Usemethod("filter_") : no applicable method for 'filter_' Applied to an Object of class "Logical"
– Joyce Maia
Can you include in the question an example of your data? Ideally the result of
dput(head(x_ordenado))
and the same thing for list values you want to delete. On the second try, you need to install the packagedplyr
:install.packages("dplyr")
.– Molx