format_zero_fill | R Documentation |
Zero-fill the species presence data by adding zero observation counts (absences) data to an existing naturecounts dataset.
format_zero_fill(
df_db,
by = "SamplingEventIdentifier",
species = "all",
fill = "ObservationCount",
extra_species = NULL,
extra_event = NULL,
warn = TRUE,
verbose = TRUE
)
df_db |
Either data frame or a connection to database with
|
by |
Character vector. By default, "SamplingEventIdentifier" or a vector of specific column names to fill by (see details) |
species |
Character vector. Either "all", for species in the data, or a vector of species ID codes to fill in. |
fill |
Character. The column name to fill in. Defaults to "ObservationCount". |
extra_species |
Character vector. Extra columns/fields uniquely
associated with |
extra_event |
Character vector. Extra columns/fields uniquely associated
with the Sampling Event (the field defined by |
warn |
Logical. If TRUE, stop zero-filling if >100 species and >1000 unique sampling events. If FALSE, ignore and proceed. |
verbose |
Logical. Show messages? |
by
refers to the combination of columns which are used to detect
missing values. By default SamplingEventIdentifier
is used. Otherwise
users can specify their own combination of columns.
If species
is supplied, all records will be used to determine observation
events, but only records (zero-filled or otherwise) which correspond to a
species in species
will be returned (all others will be omitted). Note
that records where species_id
is NA (generally for 0 counts for
presence/absence), will be converted to a list of 0's for the individual
species.
Data frame
# Download data (with "core" fields to include 'CommonName')
sample <- nc_data_dl(collection = c("SAMPLE1", "SAMPLE2"), fields_set = "core",
username = "sample", info = "nc_example")
# Remove casual observations (i.e. 'AllSpeciesReported' = "No")
library(dplyr) # For filter function
sample <- filter(sample, AllSpeciesReported == "Yes")
# Remove data with "X" ObservationCount (only keep numeric obs)
sample <- filter(sample, ObservationCount != "X")
# Zero fill by all species present
sample_all_zeros <- format_zero_fill(sample)
# Zero fill only for Canada Goose
goose <- format_zero_fill(sample, species = "230")
# Keep species-specific variables
goose <- format_zero_fill(sample, species = "230", extra_species = "CommonName")
# Keep sampling-event-specific variables
coords <- format_zero_fill(sample, extra_event = c("latitude", "longitude"))
# By species, keeping extra species variables and event variables
goose_coords <- format_zero_fill(sample, species = "230",
extra_species = "CommonName",
extra_event = c("latitude", "longitude"))
# Only return event information
events <- format_zero_fill(sample, fill = NA,
extra_event = c("latitude", "longitude"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.