Coerce a unit weight xmap_df
to a named vector or list
xmap_to_named.Rd
Checks that an xmap
has unit weights, and converts the
from
values into:
a vector for
xmap_to_named_vector()
a nested list for
xmap_to_named_list()
Details
Names are the unique target nodes in to
,
and each element contains the source node(s) in from
.
See also
Other xmap coercion:
xmap_to_matrix()
Examples
iso_vector <- c(AF = "004", AL = "008", DZ = "012", AS = "016", AD = "020")
iso_xmap <- iso_vector |>
as_pairs_from_named(names_to = "iso2c", values_to = "iso3n") |>
add_weights_unit() |>
as_xmap_df(from = iso3n, to = iso2c, weights)
#> Dropping any additional columns in
#> `add_weights_unit(as_pairs_from_named(iso_vector, names_to = "iso2c", ` and `
#> values_to = "iso3n"))`
#> ℹ To silence set `.drop_extra = TRUE`
identical(iso_vector, xmap_to_named_vector(iso_xmap))
#> [1] TRUE
animal_list <- list(
MAMM = c("elephant", "whale", "monkey"),
REPT = c("lizard", "turtle"),
CRUS = c("crab")
)
animal_xmap <- animal_list |>
as_pairs_from_named(names_to = "class", values_to = "animals") |>
add_weights_unit() |>
as_xmap_df(from = animals, to = class, weights = weights)
#> Dropping any additional columns in
#> `add_weights_unit(as_pairs_from_named(animal_list, names_to = "class", ` and `
#> values_to = "animals"))`
#> ℹ To silence set `.drop_extra = TRUE`
identical(xmap_to_named_list(animal_xmap), animal_list)
#> [1] TRUE