Skip to contents

This function filters observations from all occurrences based on the sampling_status column, typically created by the sample_observations() function.

Usage

filter_observations(observations_total, invert = FALSE)

Arguments

observations_total

An sf object with POINT geometry or a simple dataframe with sampling_status column containing values "detected". This format is typically created by the sample_observations() function.

invert

Logical. If FALSE (default), the function filters to retain only "detected" occurrences. If TRUE, it filters out "detected" occurrences and retains all other occurrences.

Value

A data frame or an sf object with POINT geometry containing the filtered observations. If invert = FALSE, the function returns detected occurrences. If invert = TRUE, it returns all other occurrences.

Examples

# Create dataframe with sampling status column
occurrences_data <- data.frame(
    time_point = 1,
    sampling_prob = seq(0.5, 1, 0.1),
    sampling_status = rep(c("undetected", "detected"), each = 3)
  )

# Keep detected occurrences
filter_observations(occurrences_data)
#>   time_point sampling_prob sampling_status
#> 4          1           0.8        detected
#> 5          1           0.9        detected
#> 6          1           1.0        detected

# Keep undetected occurrences
filter_observations(occurrences_data, invert = TRUE)
#>   time_point sampling_prob sampling_status
#> 1          1           0.5      undetected
#> 2          1           0.6      undetected
#> 3          1           0.7      undetected