create list with element names in variable in R

后端 未结 1 1322
别跟我提以往
别跟我提以往 2021-01-19 05:50

How can I get from this:

names <- c(\"a\", \"b\")
values <- c(1, 2)

To This:

list(
     list(\"a\" = 1)
    ,list(\"b         


        
相关标签:
1条回答
  • 2021-01-19 06:13

    We can use

    list(setNames(as.list(values), names))
    
    0 讨论(0)
提交回复
热议问题