How to remove a filtered dataset (check_onland) from the "original" dataset?

Hello everybody,

I need to clean my data with the check_onland function from the obistools package so that only data that is in the ocean is left. However, when I filter the data with the check_onland function, only the data that is on land is left. How can I remove this land data from my main dataset so that only marine data is left?
I tried the subset function but I don't know the specific rows that need to be removed, so I can't use it, right?

I cannot be sure if this will work with your data because I am unfamiliar with the obistools package and you have not shown any data. This code uses the anti_join function from dplyr to remove rows from DF that are in DF2

library(dplyr, warn.conflicts = FALSE)
#Invent data
set.seed(123)
DF <- data.frame(Loc1 = LETTERS[1:5],
                 Loc2 = sample(1:5))
DF
#>   Loc1 Loc2
#> 1    A    3
#> 2    B    2
#> 3    C    5
#> 4    D    4
#> 5    E    1
#Sample two rows randomly. You would use check_onland()
DF2 <- slice_sample(DF, n = 2)
DF2  
#>   Loc1 Loc2
#> 1    C    5
#> 2    A    3
#keep rows of DF not in DF2
DF_clean <- anti_join(DF, DF2)
#> Joining, by = c("Loc1", "Loc2")
DF_clean
#>   Loc1 Loc2
#> 1    B    2
#> 2    D    4
#> 3    E    1

Created on 2021-10-04 by the reprex package (v2.0.1)

1 Like

It worked! Thank you so much!!!!!! I was looking for this solution for more than a week...

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.