Creating a named list from two vectors (names, values)

前端 未结 3 1054
谎友^
谎友^ 2020-12-24 04:54

Is there a way to use mapply on two vectors to construct a named list? The first vector would be of type character and contain the names used for the list while

3条回答
  •  暖寄归人
    2020-12-24 05:51

    You can use setNames()

    setNames(as.list(c(1, 2)), c("foo", "bar"))
    

    (for a list) or

    setNames(c(1, 2), c("foo", "bar"))
    

    (for a vector)

提交回复
热议问题