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