Skip to contents

Remove rows with NA

Usage

remove_rows_with_NA(df, mapping)

Arguments

df

The dataframe for which to remove NA

mapping

The mapping list for columns in the dataframe. Names are the column types. They are free, except the species column and the observation type column, which must be coded with respectively obstype_col and spp_col (if they exist). If obstype_col is present in the names, then spp_col is assumed to be present too. Values are the corresponding column names in the dataframe.

Value

The filtered dataframe, so that rows in mapping contain no NA values. NA are allowed only in spp_col if obstype_col

is in mapping is not animal.

Examples

df <- data.frame(species = c("pigeon", "mouse", NA, "pigeon"), 
                 type = c("animal", "animal", "blank", "animal"),
                 stamp = Sys.time() + seq(60, length.out = 4, by = 60), 
                 camera = c("A", "B", "C", NA))
mapping <- list(spp_col = "species",
                obstype_col = "type",
                datetime_col = "stamp",
                cam_col = "camera")
remove_rows_with_NA(df, mapping)
#>   species   type               stamp camera
#> 1  pigeon animal 2024-06-11 12:56:41      A
#> 2   mouse animal 2024-06-11 12:57:41      B
#> 3    <NA>  blank 2024-06-11 12:58:41      C