Create a numeric vector with names in one statement?

The setNames() function is made for this purpose. As described in Advanced R and ?setNames:

test <- setNames(c(1, 2), c("A", "B"))

Leave a Comment