Collapse BIEN Trait Data by Species
collapse_BIEN_traits.Rd
Summarizes and collapses BIEN trait data by species, combining multiple trait values and author information.
Usage
collapse_BIEN_traits(
df,
species_col = "species_name",
author_cols = c("project_pi", "project_pi_contacts")
)
Arguments
- df
A data frame containing BIEN trait data, with one or more trait columns and optional author info columns.
- species_col
A string specifying the name of the species identifier column in
df
. Default is"species_name"
.A character vector of column names in
df
that contain author or project information to be concatenated. Default isc("project_pi", "project_pi_contacts")
.
Value
A data frame grouped by species with author columns collapsed into semicolon-separated strings,
numeric trait columns averaged per species (ignoring NA
s),
and non-numeric trait columns concatenated with unique values separated by semicolons.
Details
This function groups a data frame by a species identifier column, concatenates unique author information columns, and for trait columns selects the first unique non-missing value per species.
Examples
if (FALSE) { # \dontrun{
trait_data <- tibble(
scrubbed_species_binomial = c("Pinus sylvestris", "Pinus sylvestris", "Pinus sylvestris",
"Quercus robur", "Quercus robur"),
project_pi = c("Dr. Smith", "Dr. Smith", "Dr. Jones", "Dr. Brown", NA),
project_pi_contacts = c("smith@example.com", "smith@example.com", "jones@example.com", "brown@example.com", NA),
leaf_area = c(50, 50, 52, 45, 47),
seed_mass = c(100, 100, NA, 120, 115),
flower_color = c("yellow", "yellow", "green", "brown", "brown")
)
# Use the collapse_BIEN_traits function to collapse by species
collapsed_df <- collapse_BIEN_traits(df = trait_data, species_col = "scrubbed_species_binomial")
print(collapsed_df)
} # }