zip_lists | R Documentation |
This is conceptually similar to zip()
in Python, or R functions
purrr::transpose()
and data.table::transpose()
(albeit, accepting
elements in ...
instead of a single list), with one crucial difference: if
the provided objects are named, then matching is done by names, not
positions.
zip_lists(...)
... |
R lists or atomic vectors, optionally named. |
All arguments supplied must be of the same length. If positional matching is required, then all arguments provided must be unnamed. If matching by names, then all arguments must have the same set of names, but they can be in different orders.
A inverted list
gradients <- list("grad_for_wt_1", "grad_for_wt_2", "grad_for_wt_3")
weights <- list("weight_1", "weight_2", "weight_3")
str(zip_lists(gradients, weights))
str(zip_lists(gradient = gradients, weight = weights))
names(gradients) <- names(weights) <- paste0("layer_", 1:3)
str(zip_lists(gradients, weights[c(3, 1, 2)]))
names(gradients) <- paste0("gradient_", 1:3)
try(zip_lists(gradients, weights)) # error, names don't match
# call unname directly for positional matching
str(zip_lists(unname(gradients), unname(weights)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.