Closed peterdesmet closed 6 years ago
Updated approach:
# 1-5. Are identical to above
# 6. Map pathways to cbd level 1 category
mutate(cbd = recode(pathway,
"pathway_accidental" = "stowaway,contaminant",
"pathway_dispersal" = "corridor,natural_dispersal",
"pathway_import_escape" = "escape",
"import_release" = "release"
)) %>%
# 7. Update some values to cbd level 2 category based on vector
mutate(cbd = case_when(
cbd == "escape" & vector_research & vector_leisure ~ "escape_research,escape_food_bait",
cbd == "escape" & vector_research ~ "escape_research",
cbd == "escape" & vector_leisure ~ "escape_food_bait",
cbd == "release" & vector_biocontrol ~ "release_biocontrol",
TRUE ~ cbd # Leave other values as is
)) %>%
# 8. Separate commas into two columns
separate(cbd, into = c("cbd_1", "cbd_2"), sep = "\\s*\\,\\s*", remove = TRUE) %>%
# 9. Gather
gather(key, value, starts_with("cbd_"), na.rm = TRUE, convert = TRUE) %>%
# 10. Arrange
arrange(species) %>%
Close, but still not 100% correct :smile:
E.g. Acipenser baerii Brandt, 1869
has now pathway escape_food_bait
, while it is also introduced by vector industry.
I suggest to adapt the approach a bit. I would map the vector information only when (1) exclusively one vector used to introduce the species AND (2) when it maps clearly to the CBD standard. In our case, the code would look like this:
# 1 - 6. Identical
# 7 Update to cbd level 2
mutate(cbd = case_when(
cbd == "escape" &
vector_research == "Y" &
vector_leisure == "Y" &
is.na(vector_ornamental) &
is.na(vector_biocontrol) &
is.na(vector_industry) ~ "escape_research, escape_food_bait",
cbd == "escape" &
vector_research == "Y" &
is.na(vector_leisure ) &
is.na(vector_ornamental) &
is.na(vector_biocontrol) &
is.na(vector_industry) ~ "escape_research",
cbd == "escape" &
is.na(vector_research) &
vector_leisure == "Y" &
is.na(vector_ornamental) &
is.na(vector_biocontrol) &
is.na(vector_industry) ~ "escape_food_bait",
cbd == "release" &
is.na(vector_research) &
is.na(vector_leisure) &
is.na(vector_ornamental) &
vector_biocontrol == "Y" &
is.na(vector_industry) ~ "release_biocontrol",
TRUE ~ cbd # Leave rest as is
))
#8-10 Identical
For mapping pathway and vector, it is easier to only gather the pathway in rows (as we will need each one of these) and removing
NA
, but leaving the vectors as columns.Code suggestion (from Exploratory):