Q:

Transform several vectors in one list of lists

I am looking for a way to turn several vectors of the same length into a list of named lists.
For example if I have vectors:
v1 <- c("a", "b", "c")
v2 <- c("x", "y", "z")

, list should be:
list(
  list(
    name = "a",
    value = "x"
  ),
  list(
    name = "b",
    value = "y"
  )
  list(
    name = "c",
    value = "z"
  )
)

This can be useful when you generate request body for APIs that take several records in one request.

A:

This should work:
l <- mapply(
  function(name, value) list(name = name, value = value),
  v1, v2,
  USE.NAMES = FALSE, 
  SIMPLIFY = FALSE
)
str(l)

# List of 3
# $ :List of 2
#  ..$ name : chr "a"
#  ..$ value: chr "x"
# $ :List of 2
#  ..$ name : chr "b"
# ..$ value: chr "y"
# $ :List of 2
#  ..$ name : chr "c"
#  ..$ value: chr "z"

