R/move_values.R
move_values_to_new_trait_long.RdFor a dataset's custom_R_code, on data with one row per trait value. Every
row whose value in values_column is one of original_values is reassigned
to new_trait, by rewriting its traits_column. Values themselves are not
changed.
move_values_to_new_trait_long(
data,
original_trait,
new_trait,
traits_column,
values_column,
original_values,
to_lower = FALSE
)Data frame of the dataset, typically data.csv as read by the
build
Name of the trait the values are taken from. Not used for matching: see Details
Name of the trait to move the matched rows to
Name of the column holding trait names
Name of the column holding trait values
Values to move
Match original_values ignoring case? Values are compared
lower-cased but left as they are. Default FALSE.
data, with the matched rows reassigned to new_trait
Rows are matched on their value alone, whatever trait they belong to:
original_trait is not used. It is kept so that existing calls, which pass
it, still work, and so that a call reads as the trait the values are taken
from.
move_values_to_new_trait() for data with one column per trait
data <- tibble::tibble(
trait = c("Texture", "Texture", "Texture"),
value = c("plumose", "smooth", "Tomentose")
)
data %>%
move_values_to_new_trait_long(
"Texture", "seed_surface_hairs", "trait", "value",
c("plumose", "tomentose"),
to_lower = TRUE
)
#> # A tibble: 3 × 2
#> trait value
#> <chr> <chr>
#> 1 seed_surface_hairs plumose
#> 2 Texture smooth
#> 3 seed_surface_hairs Tomentose