how to create a list in R from two vectors (one would be the keys, the other the values)?

前端 未结 5 1131
离开以前
离开以前 2020-12-29 23:03

I have two vectors and I want to create a list in R where one vector are the keys and the other the values. I thought that I was going to find easily the answer in my books

5条回答
  •  悲哀的现实
    2020-12-29 23:44

    Hong's output is wrong.

    Should use vals[["key42"]]

    > vals[["key42"]]
    [1] 42
    
    vals <- 1:1000000
    keys <- paste0("key", 1:1000000)
    names(vals) <- keys
    
    vals["key42"]
    key42
       42
    

提交回复
热议问题