I am probably going to knock my head against the table because its obvious but how do you create a list programatically from a character vector such that the character vector provides the tags and a nother vector the values. E.g.
character.vector <- c('first.element', 'second.element')
values.vector <- c(1, 2)
a.list <- list(//magic here//)
print(a.list) // prints the same as list(first.element=1, second.element=2)
character.vector <- c('first.element', 'second.element')
values.vector <- c(1, 2)
as.list(setNames(values.vector, character.vector))
You could set:
> names(values.vector) <- character.vector
> values.vector
first.element second.element
1 2
and, of course, convert it into a list if necessary:
> as.list(values.vector)
$first.element
[1] 1
$second.element
[1] 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With